diff --git a/src/components/editor/CustomEditor.vue b/src/components/editor/CustomEditor.vue index 73b0ff4..754f90f 100644 --- a/src/components/editor/CustomEditor.vue +++ b/src/components/editor/CustomEditor.vue @@ -783,6 +783,20 @@ const onSubscribeMention = (data) => { // 确保编辑器获得焦点 editorRef.value?.focus() + // 如果编辑器为空或者光标不在编辑器内,将光标移动到编辑器末尾 + const selection = window.getSelection() + if (!selection.rangeCount || !editorRef.value.contains(selection.anchorNode)) { + const range = document.createRange() + if (editorRef.value.lastChild) { + range.setStartAfter(editorRef.value.lastChild) + } else { + range.setStart(editorRef.value, 0) + } + range.collapse(true) + selection.removeAllRanges() + selection.addRange(range) + } + // 插入@提及 insertMention(data) } diff --git a/src/constant/event-bus.ts b/src/constant/event-bus.ts index a437264..3abbb99 100644 --- a/src/constant/event-bus.ts +++ b/src/constant/event-bus.ts @@ -5,5 +5,6 @@ export const enum ContactConst { export const enum EditorConst { Mention = 'editor:mention', Quote = 'editor:quote', - Edit = 'editor:edit' + Edit = 'editor:edit', + Clear = 'editor:clear' }