mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 23:55:23 +00:00
fix(shortcuts): prevent accidental double-Shift palette activation (#1519)
This commit is contained in:
1 parent
7d06686f62
commit
cbbb80bc82
3 files changed
+121
-19
No files matched your search
@@ -25,3 +25,35 @@ export function dispatchCtrlW(target: EventTarget | null) {
|
||||
});
|
||||
return !target.dispatchEvent(event);
|
||||
}
|
||||
|
||||
/** Match two consecutive Shift presses, never a typing or IME sequence. */
|
||||
export function createCommandPaletteShortcutMatcher() {
|
||||
let lastShift: number | null = null;
|
||||
const reset = () => {
|
||||
lastShift = null;
|
||||
};
|
||||
const matches = (event: KeyboardEvent, now = Date.now()): boolean => {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.isComposing ||
|
||||
event.keyCode === 229 ||
|
||||
event.repeat ||
|
||||
event.altKey
|
||||
) {
|
||||
reset();
|
||||
return false;
|
||||
}
|
||||
if (isShiftKey(event) && !event.ctrlKey && !event.metaKey) {
|
||||
const matched = lastShift !== null && now - lastShift < 300;
|
||||
lastShift = matched ? null : now;
|
||||
return matched;
|
||||
}
|
||||
reset();
|
||||
return (
|
||||
(event.ctrlKey || event.metaKey) &&
|
||||
!event.shiftKey &&
|
||||
event.code === "KeyK"
|
||||
);
|
||||
};
|
||||
return { matches, reset };
|
||||
}
|
||||
Reference in new issue
Block a user