Skip to content

Commit cf7ca9b

Browse files
authored
fix(app): skip editor reconcile during IME composition (anomalyco#17041)
1 parent 981c7b9 commit cf7ca9b

1 file changed

Lines changed: 31 additions & 16 deletions

File tree

packages/app/src/components/prompt-input.tsx

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,18 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
490490
setComposing(false)
491491
}
492492

493+
const handleCompositionStart = () => {
494+
setComposing(true)
495+
}
496+
497+
const handleCompositionEnd = () => {
498+
setComposing(false)
499+
requestAnimationFrame(() => {
500+
if (composing()) return
501+
reconcile(prompt.current().filter((part) => part.type !== "image"))
502+
})
503+
}
504+
493505
const agentList = createMemo(() =>
494506
sync.data.agent
495507
.filter((agent) => !agent.hidden && agent.mode !== "primary")
@@ -680,24 +692,27 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
680692
}
681693
}
682694

683-
createEffect(
684-
on(
685-
() => prompt.current(),
686-
(currentParts) => {
687-
const inputParts = currentParts.filter((part) => part.type !== "image")
695+
const reconcile = (input: Prompt) => {
696+
if (mirror.input) {
697+
mirror.input = false
698+
if (isNormalizedEditor()) return
688699

689-
if (mirror.input) {
690-
mirror.input = false
691-
if (isNormalizedEditor()) return
700+
renderEditorWithCursor(input)
701+
return
702+
}
692703

693-
renderEditorWithCursor(inputParts)
694-
return
695-
}
704+
const dom = parseFromDOM()
705+
if (isNormalizedEditor() && isPromptEqual(input, dom)) return
696706

697-
const domParts = parseFromDOM()
698-
if (isNormalizedEditor() && isPromptEqual(inputParts, domParts)) return
707+
renderEditorWithCursor(input)
708+
}
699709

700-
renderEditorWithCursor(inputParts)
710+
createEffect(
711+
on(
712+
() => prompt.current(),
713+
(parts) => {
714+
if (composing()) return
715+
reconcile(parts.filter((part) => part.type !== "image"))
701716
},
702717
),
703718
)
@@ -1208,8 +1223,8 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
12081223
spellcheck={store.mode === "normal"}
12091224
onInput={handleInput}
12101225
onPaste={handlePaste}
1211-
onCompositionStart={() => setComposing(true)}
1212-
onCompositionEnd={() => setComposing(false)}
1226+
onCompositionStart={handleCompositionStart}
1227+
onCompositionEnd={handleCompositionEnd}
12131228
onBlur={handleBlur}
12141229
onKeyDown={handleKeyDown}
12151230
classList={{

0 commit comments

Comments
 (0)