From 2f094ab3321db5663a7e3a07f401a3802114c4c8 Mon Sep 17 00:00:00 2001 From: zhangyahui Date: Fri, 13 Mar 2026 14:25:44 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E6=8A=A5=E5=91=8A=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/home/components/Input.vue | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/views/home/components/Input.vue b/src/views/home/components/Input.vue index f0529eb..4dc8e35 100644 --- a/src/views/home/components/Input.vue +++ b/src/views/home/components/Input.vue @@ -378,7 +378,12 @@ // Insert tag at the current cursor position const selection = window.getSelection() - if (selection && selection.rangeCount > 0) { + + // 检查selection是否在editorRef内部,不在则强制使用editorRef + const isInEditor = + editorRef.value && selection && editorRef.value.contains(selection.anchorNode) + + if (isInEditor && selection && selection.rangeCount > 0) { const range = selection.getRangeAt(0) range.insertNode(tag) @@ -397,7 +402,7 @@ // ensure editor has focus editorRef.value && (editorRef.value as HTMLElement).focus() } else if (editorRef.value) { - // If no selection, append directly to editor and place caret after + // If no selection in editor, append directly to editor and place caret after editorRef.value.appendChild(tag) const zwsp = document.createTextNode('\u200B') editorRef.value.appendChild(zwsp)