fix: render composing text error

pr675
Hufe921 3 years ago
parent 266915af09
commit 310e0e91fb

@ -7,23 +7,27 @@ function compositionstart(host: CanvasEvent) {
function compositionend(host: CanvasEvent, evt: CompositionEvent) { function compositionend(host: CanvasEvent, evt: CompositionEvent) {
host.isComposing = false host.isComposing = false
removeComposingInput(host) // 处理输入框关闭
const draw = host.getDraw() const draw = host.getDraw()
const cursor = draw.getCursor() // 不存在值:删除合成输入
// 合成结果不存在(输入框关闭)无法触发input事件需手动触发渲染
if (!evt.data) { if (!evt.data) {
const agentText = cursor.getAgentDomValue() removeComposingInput(host)
if (agentText) { const rangeManager = draw.getRange()
input(agentText, host) const { endIndex: curIndex } = rangeManager.getRange()
} else { draw.render({
const rangeManager = draw.getRange() curIndex,
const { endIndex: curIndex } = rangeManager.getRange() isSubmitHistory: false
draw.render({ })
curIndex } else {
}) // 存在值无法触发input事件需手动检测并触发渲染
} setTimeout(() => {
if (host.compositionInfo) {
input(evt.data, host)
}
})
} }
// 移除代理输入框数据 // 移除代理输入框数据
const cursor = draw.getCursor()
cursor.clearAgentDomValue() cursor.clearAgentDomValue()
} }

@ -12,18 +12,19 @@ export function input(data: string, host: CanvasEvent) {
const position = draw.getPosition() const position = draw.getPosition()
const cursorPosition = position.getCursorPosition() const cursorPosition = position.getCursorPosition()
if (!data || !cursorPosition) return if (!data || !cursorPosition) return
const isComposing = host.isComposing
// 正在合成文本进行非输入操作
if (isComposing && host.compositionInfo?.value === data) return
const control = draw.getControl() const control = draw.getControl()
if (control.isPartRangeInControlOutside()) { if (control.isPartRangeInControlOutside()) {
// 忽略选区部分在控件的输入 // 忽略选区部分在控件的输入
return return
} }
const isComposing = host.isComposing
// 移除合成输入 // 移除合成输入
removeComposingInput(host)
if (!isComposing) { if (!isComposing) {
const cursor = draw.getCursor() const cursor = draw.getCursor()
cursor.clearAgentDomValue() cursor.clearAgentDomValue()
} else {
removeComposingInput(host)
} }
const activeControl = control.getActiveControl() const activeControl = control.getActiveControl()
const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE } = ElementType const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE } = ElementType

Loading…
Cancel
Save