Repository navigation
fix(dashboard): forward dead-key composition input to chat PTY #76257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1c3e52
test(dashboard): reproduce dropped dead-key composition input
dplush 8e36193
fix(dashboard): forward committed dead-key input to PTY
dplush 8a1ac8e
fix(dashboard): defer IME fallback until xterm input settles
dplush 49956c4
test(dashboard): cover IME fallback lifecycle
dplush 9127bcc
fix(dashboard): avoid duplicate IME fallback input
dplush b3afbed
fix(dashboard): keep mouse input out of IME fallback
dplush dc800e8
fix(dashboard): preserve consecutive IME composition input
dplush 72311e8
fix(dashboard): retain composition after unrelated input
dplush 89a46d7
fix(dashboard): handle chunked IME composition input
dplush ee0bcb0
test(dashboard): cover delayed IME fallback after unrelated input
dplush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { createPtyCompositionForwarder } from "./pty-composition"; | ||
|
|
||
| describe("createPtyCompositionForwarder", () => { | ||
| afterEach(() => vi.useRealTimers()); | ||
|
|
||
| it("forwards committed dead-key text when xterm emits no onData", () => { | ||
| vi.useFakeTimers(); | ||
| const send = vi.fn(); | ||
| const forwarder = createPtyCompositionForwarder(send); | ||
|
|
||
| forwarder.onCompositionEnd("ä"); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(send).toHaveBeenCalledExactlyOnceWith("ä"); | ||
| }); | ||
|
|
||
| it("leaves xterm's committed input alone when it arrives before the fallback", () => { | ||
| vi.useFakeTimers(); | ||
| const send = vi.fn(); | ||
| const forwarder = createPtyCompositionForwarder(send); | ||
|
|
||
| forwarder.onCompositionEnd("ä"); | ||
| forwarder.noteTerminalData("äx"); | ||
| vi.runAllTimers(); | ||
|
|
||
| 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("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(); | ||
|
|
||
| expect(send).toHaveBeenNthCalledWith(1, "a"); | ||
| expect(send).toHaveBeenNthCalledWith(2, "ä"); | ||
| }); | ||
|
|
||
| it("cancels a pending composition on disposal", () => { | ||
| vi.useFakeTimers(); | ||
| const send = vi.fn(); | ||
| const forwarder = createPtyCompositionForwarder(send); | ||
|
|
||
| forwarder.onCompositionEnd("ä"); | ||
| forwarder.dispose(); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(send).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("does not send an empty cancelled composition", () => { | ||
| vi.useFakeTimers(); | ||
| const send = vi.fn(); | ||
| const forwarder = createPtyCompositionForwarder(send); | ||
|
|
||
| forwarder.onCompositionEnd(""); | ||
| vi.runAllTimers(); | ||
|
|
||
| expect(send).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * Delays an IME/dead-key commit just long enough for xterm to emit onData. | ||
| * | ||
| * xterm is authoritative when it emits the commit. Browsers/layouts where it | ||
| * does not emit onData still forward the compositionend text on the next turn. | ||
| */ | ||
| export function createPtyCompositionForwarder(send: (data: string) => void) { | ||
| let pending: string | null = null; | ||
| let timer: ReturnType<typeof setTimeout> | null = null; | ||
|
|
||
| const clearPending = () => { | ||
| pending = null; | ||
| if (timer) { | ||
| clearTimeout(timer); | ||
| timer = null; | ||
| } | ||
| }; | ||
|
|
||
| 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; | ||
| clearPending(); | ||
| if (committed) send(committed); | ||
| }, 16); | ||
| }, | ||
| 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, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clears a pending
"ä"for any non-ESC terminal payload, including an unrelated next keystroke such as"x"during the 16 ms grace interval; then the fallback never sends"ä". Please correlate cancellation with the pending composition and add that regression case.