fix(desktop): hold-to-quit no longer strands the quit (#11016)
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
0eaa18c129
commit
095d57552c
2 files changed
+27
-10
No files matched your search
@@ -178,14 +178,35 @@ describe("makeQuitShortcutHandler", () => {
|
||||
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200);
|
||||
await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false }));
|
||||
harness.preventDefault.mockClear();
|
||||
await harness.send(makeInput({ meta: false, isAutoRepeat: true }));
|
||||
expect(harness.preventDefault).toHaveBeenCalledTimes(1);
|
||||
vi.advanceTimersByTime(QUIT_HOLD_RELEASE_GRACE_MS * 2);
|
||||
// Repeats without the modifier prove Q is still down, so they hold the
|
||||
// quit back for as long as they keep arriving.
|
||||
await harness.holdFor(QUIT_HOLD_RELEASE_GRACE_MS * 2, { meta: false });
|
||||
expect(harness.preventDefault).toHaveBeenCalled();
|
||||
expect(harness.quit).not.toHaveBeenCalled();
|
||||
await harness.send(makeInput({ type: "keyUp", meta: false }));
|
||||
expect(harness.quit).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("commits a concealed hold when the last Q repeat is never released", async () => {
|
||||
// macOS can drop the final Q keyUp. The quit must land on its own once
|
||||
// repeats stop, rather than sitting armed until an unrelated key arrives.
|
||||
const harness = makeHarness();
|
||||
await harness.send(makeInput({}));
|
||||
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200);
|
||||
await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false }));
|
||||
await harness.send(makeInput({ meta: false, isAutoRepeat: true }));
|
||||
|
||||
vi.advanceTimersByTime(QUIT_HOLD_RELEASE_GRACE_MS);
|
||||
expect(harness.quit).toHaveBeenCalledTimes(1);
|
||||
|
||||
// A lone Cmd tap afterwards must not quit a second time.
|
||||
harness.quit.mockClear();
|
||||
await harness.send(makeInput({ key: "Meta" }));
|
||||
await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false }));
|
||||
vi.advanceTimersByTime(QUIT_HOLD_RELEASE_GRACE_MS * 4);
|
||||
expect(harness.quit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not quit when the hold stops before the duration", async () => {
|
||||
const harness = makeHarness();
|
||||
await harness.send(makeInput({}));
|
||||
|
||||
@@ -125,13 +125,9 @@ export function makeQuitShortcutHandler(
|
||||
}
|
||||
if (quitOnRelease) {
|
||||
event.preventDefault();
|
||||
if (key === "q") {
|
||||
if (modifierDown) {
|
||||
quitAfterQuietPeriod();
|
||||
} else {
|
||||
clearWatchdog();
|
||||
}
|
||||
}
|
||||
// A Q keydown proves the key is still down whether or not the modifier
|
||||
// is still held, so it only pushes the quiet period back.
|
||||
if (key === "q") quitAfterQuietPeriod();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user