Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): delete shortcut key not working
Elian Doranb450a4faa0c6
diff --git a/apps/client/src/services/shortcuts.spec.ts b/apps/client/src/services/shortcuts.spec.tsindex 405c713596..d9c2547a9b 100644--- a/apps/client/src/services/shortcuts.spec.ts+++ b/apps/client/src/services/shortcuts.spec.ts@@ -148,13 +148,19 @@ describe("shortcuts", () => {expect(matchesShortcut(event, "a")).toBe(false);});- it("should match function keys even with no modifiers", () => {+ it("should match some keys even with no modifiers", () => {+ // Bare function keyslet event = createKeyboardEvent({ key: "F1", code: "F1" });expect(matchesShortcut(event, "F1")).toBeTruthy();expect(matchesShortcut(event, "f1")).toBeTruthy();+ // Function keys with shiftevent = createKeyboardEvent({ key: "F1", code: "F1", shiftKey: true });expect(matchesShortcut(event, "Shift+F1")).toBeTruthy();++ // Delete+ event = createKeyboardEvent({ key: "Delete", code: "Delete" });+ expect(matchesShortcut(event, "Delete")).toBeTruthy();});it("should handle alternative modifier names", () => {diff --git a/apps/client/src/services/shortcuts.ts b/apps/client/src/services/shortcuts.tsindex 92bb02d667..5e8cd52a59 100644--- a/apps/client/src/services/shortcuts.ts+++ b/apps/client/src/services/shortcuts.ts@@ -36,10 +36,18 @@ const keyMap: { [key: string]: string[] } = {};// Function keys+const functionKeyCodes: string[] = [];for (let i = 1; i <= 19; i++) {- keyMap[`f${i}`] = [`F${i}`];+ const keyCode = `F${i}`;+ functionKeyCodes.push(keyCode);+ keyMap[`f${i}`] = [ keyCode ];}+const KEYCODES_WITH_NO_MODIFIER = new Set([+ "Delete",+ ...functionKeyCodes+]);+/*** Check if IME (Input Method Editor) is composing* This is used to prevent keyboard shortcuts from firing during IME composition@@ -163,8 +171,8 @@ export function matchesShortcut(e: KeyboardEvent, shortcut: string): boolean {const expectedMeta = modifiers.includes('meta') || modifiers.includes('cmd') || modifiers.includes('command');// Refuse key combinations that don't include modifiers because they interfere with the normal usage of the application.- // Function keys are an exception.- if (!(expectedCtrl || expectedAlt || expectedShift || expectedMeta) && !/f\d+/.test(key)) {+ // Some keys such as function keys are an exception.+ if (!(expectedCtrl || expectedAlt || expectedShift || expectedMeta) && !KEYCODES_WITH_NO_MODIFIER.has(e.code)) {return false;}