From 310e0e91fbe4ef64343b5cc746ec4e7d471df974 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Sat, 1 Apr 2023 13:28:08 +0800 Subject: [PATCH] fix: render composing text error --- src/editor/core/event/handlers/composition.ts | 30 +++++++++++-------- src/editor/core/event/handlers/input.ts | 7 +++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/editor/core/event/handlers/composition.ts b/src/editor/core/event/handlers/composition.ts index a6cff8d..9dac74c 100644 --- a/src/editor/core/event/handlers/composition.ts +++ b/src/editor/core/event/handlers/composition.ts @@ -7,23 +7,27 @@ function compositionstart(host: CanvasEvent) { function compositionend(host: CanvasEvent, evt: CompositionEvent) { host.isComposing = false - removeComposingInput(host) + // 处理输入框关闭 const draw = host.getDraw() - const cursor = draw.getCursor() - // 合成结果不存在(输入框关闭),无法触发input事件需手动触发渲染 + // 不存在值:删除合成输入 if (!evt.data) { - const agentText = cursor.getAgentDomValue() - if (agentText) { - input(agentText, host) - } else { - const rangeManager = draw.getRange() - const { endIndex: curIndex } = rangeManager.getRange() - draw.render({ - curIndex - }) - } + removeComposingInput(host) + const rangeManager = draw.getRange() + const { endIndex: curIndex } = rangeManager.getRange() + draw.render({ + curIndex, + isSubmitHistory: false + }) + } else { + // 存在值:无法触发input事件需手动检测并触发渲染 + setTimeout(() => { + if (host.compositionInfo) { + input(evt.data, host) + } + }) } // 移除代理输入框数据 + const cursor = draw.getCursor() cursor.clearAgentDomValue() } diff --git a/src/editor/core/event/handlers/input.ts b/src/editor/core/event/handlers/input.ts index a5aae9b..3154283 100644 --- a/src/editor/core/event/handlers/input.ts +++ b/src/editor/core/event/handlers/input.ts @@ -12,18 +12,19 @@ export function input(data: string, host: CanvasEvent) { const position = draw.getPosition() const cursorPosition = position.getCursorPosition() if (!data || !cursorPosition) return + const isComposing = host.isComposing + // 正在合成文本进行非输入操作 + if (isComposing && host.compositionInfo?.value === data) return const control = draw.getControl() if (control.isPartRangeInControlOutside()) { // 忽略选区部分在控件的输入 return } - const isComposing = host.isComposing // 移除合成输入 + removeComposingInput(host) if (!isComposing) { const cursor = draw.getCursor() cursor.clearAgentDomValue() - } else { - removeComposingInput(host) } const activeControl = control.getActiveControl() const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE } = ElementType