fix(dashboard): avoid duplicate IME fallback input
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user