Skip to content

Commit cb49e31

Browse files
committed
fix(core): reset pending chord only on mouse down
1 parent 1197ed9 commit cb49e31

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/core/src/app/createApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ export function createApp<S>(
732732
if (keybindingsEnabled) {
733733
if (
734734
ev.kind === "mouse" &&
735-
(ev.mouseKind === 3 || ev.mouseKind === 4) &&
735+
ev.mouseKind === 3 &&
736736
keybindingState.chordState.pendingKeys.length > 0
737737
) {
738738
keybindingState = Object.freeze({

packages/core/src/keybindings/__tests__/keybinding.conflicts.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,30 @@ describe("app routing precedence", () => {
409409
assert.equal(chordHits, 0);
410410
});
411411

412+
test("mouse up does not clear chord started after mouse down", async () => {
413+
const backend = new StubBackend();
414+
let chordHits = 0;
415+
416+
const app = createApp({ backend, initialState: 0 });
417+
app.keys({
418+
"g g": () => {
419+
chordHits++;
420+
},
421+
});
422+
app.view(() => ui.text("No focusable widgets"));
423+
424+
await app.start();
425+
await pushEvents(backend, [{ kind: "resize", timeMs: 1, cols: 40, rows: 10 }]);
426+
await settleNextFrame(backend);
427+
428+
await pushEvents(backend, [{ kind: "mouse", timeMs: 2, x: 0, y: 0, mouseKind: 3, buttons: 1 }]);
429+
await pushEvents(backend, [{ kind: "key", timeMs: 3, key: KEY_G, action: "down" }]);
430+
await pushEvents(backend, [{ kind: "mouse", timeMs: 4, x: 0, y: 0, mouseKind: 4, buttons: 0 }]);
431+
await pushEvents(backend, [{ kind: "key", timeMs: 5, key: KEY_G, action: "down" }]);
432+
433+
assert.equal(chordHits, 1);
434+
});
435+
412436
test("app-level keybinding consumes Enter before widget-level button routing", async () => {
413437
const backend = new StubBackend();
414438
let keybindingHits = 0;

0 commit comments

Comments
 (0)