Skip to content

The agent that grows with you

fix(dashboard): preserve consecutive IME composition input

Denis Ha428531ef653
diff --git a/web/src/lib/pty-composition.test.ts b/web/src/lib/pty-composition.test.ts
index d60761857e0..0a0189320c6 100644
--- a/web/src/lib/pty-composition.test.ts
+++ b/web/src/lib/pty-composition.test.ts
@@ -28,38 +28,38 @@ describe("createPtyCompositionForwarder", () => {
expect(send).not.toHaveBeenCalled();
});
- it("prefers xterm input in the grace window over the fallback", () => {
+ it("forwards a second composition after the first fallback completes", () => {
vi.useFakeTimers();
const send = vi.fn();
const forwarder = createPtyCompositionForwarder(send);
forwarder.onCompositionEnd("ä");
- forwarder.noteTerminalData("x");
+ vi.runAllTimers();
+ forwarder.onCompositionEnd("ö");
vi.runAllTimers();
- expect(send).not.toHaveBeenCalled();
+ expect(send).toHaveBeenNthCalledWith(1, "ä");
+ expect(send).toHaveBeenNthCalledWith(2, "ö");
});
- it("forwards a second composition after the first fallback completes", () => {
+ it("preserves an earlier rapid composition before scheduling the next", () => {
vi.useFakeTimers();
const send = vi.fn();
const forwarder = createPtyCompositionForwarder(send);
+ forwarder.onCompositionEnd("a");
forwarder.onCompositionEnd("ä");
vi.runAllTimers();
- forwarder.onCompositionEnd("ö");
- vi.runAllTimers();
- expect(send).toHaveBeenNthCalledWith(1, "ä");
- expect(send).toHaveBeenNthCalledWith(2, "ö");
+ expect(send).toHaveBeenNthCalledWith(1, "a");
+ expect(send).toHaveBeenNthCalledWith(2, "ä");
});
- it("supersedes an earlier composition and cancels it on disposal", () => {
+ it("cancels a pending composition on disposal", () => {
vi.useFakeTimers();
const send = vi.fn();
const forwarder = createPtyCompositionForwarder(send);
- forwarder.onCompositionEnd("a");
forwarder.onCompositionEnd("ä");
forwarder.dispose();
vi.runAllTimers();
diff --git a/web/src/lib/pty-composition.ts b/web/src/lib/pty-composition.ts
index 6eec3d5a221..0fd7367c98f 100644
--- a/web/src/lib/pty-composition.ts
+++ b/web/src/lib/pty-composition.ts
@@ -19,7 +19,10 @@ export function createPtyCompositionForwarder(send: (data: string) => void) {
return {
onCompositionEnd(data: string | null) {
if (!data) return;
+ // Preserve rapid consecutive commits instead of discarding the first.
+ const previous = pending;
clearPending();
+ if (previous) send(previous);
pending = data;
timer = setTimeout(() => {
const committed = pending;
@@ -27,11 +30,10 @@ export function createPtyCompositionForwarder(send: (data: string) => void) {
if (committed) send(committed);
}, 16);
},
- noteTerminalData() {
- // 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();
+ noteTerminalData(data: string) {
+ // A non-protocol xterm input in the short grace window is its own
+ // composition delivery (possibly chunked or normalization-different).
+ if (pending && !data.startsWith("\x1b")) clearPending();
},
dispose: clearPending,
};
diff --git a/web/src/pages/ChatPage.tsx b/web/src/pages/ChatPage.tsx
index 00538e5915c..cfda855f390 100644
--- a/web/src/pages/ChatPage.tsx
+++ b/web/src/pages/ChatPage.tsx
@@ -1316,7 +1316,7 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
sendComposedText = (data) => forwardPtyData(data, false);
onDataDisposable = term.onData((data) => {
if (!SGR_MOUSE_RE.test(data)) {
- compositionForwarder.noteTerminalData();
+ compositionForwarder.noteTerminalData(data);
}
forwardPtyData(data);
});