From f86f8343ef1156ad456abd83163c5814d3e1fe91 Mon Sep 17 00:00:00 2001 From: ByungCheol Date: Sun, 7 Jun 2026 17:30:26 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20=EC=97=90?= =?UTF-8?q?=EB=94=94=ED=84=B0=20=ED=95=9C=EA=B8=80=20IME=20=EC=B2=AB=20?= =?UTF-8?q?=EC=9E=90=EC=9D=8C=20=EC=A4=91=EB=B3=B5=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MarkdownEditor: IME 조합(compositionstart~end) 중에는 getMarkdown/emit 보류, 조합 완료 시 한 번만 반영 → 조합 중 직렬화로 자음이 중복되던('ㅅ사') 문제 해소 - 조합 중에는 watch 의 setMarkdown 도 건너뜀 Co-Authored-By: Claude Opus 4.8 --- src/components/editor/MarkdownEditor.vue | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/components/editor/MarkdownEditor.vue b/src/components/editor/MarkdownEditor.vue index 8909924..b2382bc 100644 --- a/src/components/editor/MarkdownEditor.vue +++ b/src/components/editor/MarkdownEditor.vue @@ -18,6 +18,21 @@ const el = ref(null) let editor = null // 에디터가 마지막으로 emit 한 값. 부모가 되돌려준 echo 를 구분해 한글 조합(IME)이 깨지지 않게 한다. let lastEmitted = props.modelValue || '' +// IME(한글 등) 조합 중 여부. 조합 중에는 getMarkdown/emit 을 보류해 첫 자음이 중복되는 문제를 막는다. +let composing = false + +function emitValue() { + if (!editor) return + lastEmitted = editor.getMarkdown() + emit('update:modelValue', lastEmitted) +} +function onCompStart() { + composing = true +} +function onCompEnd() { + composing = false + emitValue() // 조합 완료 시 한 번만 반영 +} onMounted(() => { editor = new Editor({ @@ -32,20 +47,24 @@ onMounted(() => { autofocus: false, events: { change: () => { - lastEmitted = editor.getMarkdown() - emit('update:modelValue', lastEmitted) + // 조합 중에는 보류 — 조합 중 getMarkdown 호출이 IME 를 끊어 자음 중복을 유발한다. + if (composing) return + emitValue() }, }, }) + // 조합 이벤트는 contenteditable 에서 버블링되어 래퍼(el)에서 잡힌다. + el.value.addEventListener('compositionstart', onCompStart) + el.value.addEventListener('compositionend', onCompEnd) }) // 외부 값 변경(수정 로드, 제출 후 초기화 등)만 에디터에 반영. -// 에디터 자신이 방금 emit 한 값(echo)이면 무시 → 입력 중 setMarkdown 으로 IME(한글) 조합이 끊기지 않게 한다. +// 에디터 자신이 방금 emit 한 값(echo)이거나 조합 중이면 무시 → 입력 중 setMarkdown 으로 IME 조합이 끊기지 않게 한다. watch( () => props.modelValue, (val) => { const v = val || '' - if (v === lastEmitted) return + if (composing || v === lastEmitted) return if (editor && v !== editor.getMarkdown()) { lastEmitted = v editor.setMarkdown(v) @@ -54,6 +73,10 @@ watch( ) onBeforeUnmount(() => { + if (el.value) { + el.value.removeEventListener('compositionstart', onCompStart) + el.value.removeEventListener('compositionend', onCompEnd) + } editor?.destroy() editor = null })