From b18a6e5432330bd604812e5c8071a93a39711b97 Mon Sep 17 00:00:00 2001 From: Phoenix <64720302+Concur-max@users.noreply.github.com> Date: Fri, 6 Jun 2025 12:00:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BC=96=E8=BE=91=E5=99=A8):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B8=85=E9=99=A4=E4=BA=8B=E4=BB=B6=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=8F=90=E5=8F=8A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在事件总线常量中添加 editor:clear 事件类型 优化提及功能,确保编辑器获得焦点后光标位置正确 --- src/components/editor/CustomEditor.vue | 14 ++++++++++++++ src/constant/event-bus.ts | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) 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' }