Fixed #2829 - Editor | new selection-change event

pull/2835/head
Tuğçe Küçükoğlu 2022-08-05 11:09:36 +03:00
parent 62c8299319
commit 33a259d657
4 changed files with 83 additions and 7 deletions

View File

@ -64,13 +64,38 @@ const EditorEvents = [
]
},
{
name: "input",
description: "Callback to invoke when text of editor changes.",
name: "selection-change",
description: "Callback to invoke when selection of the text changes.",
arguments: [
{
name: "event",
name: "event.range",
type: "object",
description: "Representation of the selection boundaries."
},
{
name: "event.oldRange",
type: "string",
description: 'Representation of the previous selection boundaries.'
},
{
name: "event.source",
type: "string",
description: 'Source of change. Will be either "user" or "api".'
},
{
name: "event.htmlValue",
type: "string",
description: "Current value as html."
},
{
name: "event.textValue",
type: "string",
description: "Current value as text."
},
{
name: "event.instance",
type: "object",
description: "Text editor instance."
}
]
}

View File

@ -24,6 +24,33 @@ export interface EditorTextChangeEvent {
instance: any;
}
export interface EditorSelectionChangeEvent {
/**
* Current value as html.
*/
htmlValue: string;
/**
* Current value as text.
*/
textValue: any;
/**
* Representation of the selection boundaries.
*/
range: any;
/**
* Representation of the previous selection boundaries.
*/
oldRange: any;
/**
* Source of change. Will be either 'user' or 'api'.
*/
source: string;
/**
* Text editor instance.
*/
instance: any;
}
export interface EditorProps {
/**
* Value of the content.
@ -65,6 +92,11 @@ export declare type EditorEmits = {
* @param {EditorTextChangeEvent} event - Custom text change event.
*/
'text-change': (event: EditorTextChangeEvent) => void;
/**
* Callback to invoke when selection of the text changes.
* @param {EditorSelectionChangeEvent} event - Custom selection change event.
*/
'selection-change': (event: EditorTextChangeEvent) => void;
}
declare class Editor extends ClassComponent<EditorProps, EditorSlots, EditorEmits> { }

View File

@ -52,7 +52,7 @@ import Quill from "quill";
export default {
name: 'Editor',
emits: ['update:modelValue', 'text-change'],
emits: ['update:modelValue', 'text-change', 'selection-change'],
props: {
modelValue: String,
placeholder: String,
@ -99,6 +99,20 @@ export default {
});
}
});
this.quill.on('selection-change', (range, oldRange, source) => {
let html = this.$refs.editorElement.children[0].innerHTML;
let text = this.quill.getText().trim();
this.$emit('selection-change', {
htmlValue: html,
textValue: text,
range: range,
oldRange: oldRange,
source: source,
instance: this.quill
})
});
},
methods: {
renderValue(value) {

View File

@ -103,9 +103,14 @@ import Editor from 'primevue/editor';
<td>Callback to invoke when text of editor changes.</td>
</tr>
<tr>
<td>input</td>
<td>event: Current value as html.</td>
<td>Callback to invoke when text of editor changes.</td>
<td>selection-change</td>
<td>event.range: Representation of the selection boundaries.<br/>
event.oldRange: Representation of the previous selection boundaries.<br/>
event.source: Source of change. Will be either "user" or "api".<br/>
event.htmlValue: Current value as html.<br/>
event.textValue: Current value as text.<br/>
event.instance: Text editor instance.</td>
<td>Callback to invoke when selection of the text changes.</td>
</tr>
</tbody>
</table>