fix(dashboard): avoid duplicate IME fallback input

This commit is contained in:
Denis H
2026-08-01 17:33:21 +02:00
committed by Teknium
parent c066b5a1d3
commit 3d9fdb2e2b
3 changed files with 26 additions and 8 deletions
+16 -2
View File
@@ -28,7 +28,7 @@ describe("createPtyCompositionForwarder", () => {
expect(send).not.toHaveBeenCalled();
});
it("keeps the fallback pending when xterm emits unrelated input", () => {
it("prefers xterm input in the grace window over the fallback", () => {
vi.useFakeTimers();
const send = vi.fn();
const forwarder = createPtyCompositionForwarder(send);
@@ -37,7 +37,21 @@ describe("createPtyCompositionForwarder", () => {
forwarder.noteTerminalData("x");
vi.runAllTimers();
expect(send).toHaveBeenCalledExactlyOnceWith("ä");
expect(send).not.toHaveBeenCalled();
});
it("forwards a second composition after the first fallback completes", () => {
vi.useFakeTimers();
const send = vi.fn();
const forwarder = createPtyCompositionForwarder(send);
forwarder.onCompositionEnd("ä");
vi.runAllTimers();
forwarder.onCompositionEnd("ö");
vi.runAllTimers();
expect(send).toHaveBeenNthCalledWith(1, "ä");
expect(send).toHaveBeenNthCalledWith(2, "ö");
});
it("supersedes an earlier composition and cancels it on disposal", () => {
+6 -5
View File
@@ -25,12 +25,13 @@ export function createPtyCompositionForwarder(send: (data: string) => void) {
const committed = pending;
clearPending();
if (committed) send(committed);
}, 0);
}, 16);
},
noteTerminalData(data: string) {
if (pending && data.startsWith(pending)) {
clearPending();
}
noteTerminalData(_data: string) {
// Any xterm input in the short grace window is its own composition
// delivery (possibly chunked or normalization-different), so prefer it
// over the fallback to avoid duplicate text.
if (pending) clearPending();
},
dispose: clearPending,
};
+4 -1
View File
@@ -1313,7 +1313,10 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
// The deferred composition fallback is already committed text, so it
// must not consume the mobile replacement window intended for xterm's
// normal onData path.
sendComposedText = (data) => forwardPtyData(data, false);
sendComposedText = (data) => {
forwardPtyData(data, false);
mobileReplacementInputUntilRef.current = 0;
};
onDataDisposable = term.onData((data) => {
compositionForwarder.noteTerminalData(data);
forwardPtyData(data);