Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): render arrow-key shortcuts as glyphs (↑ ↓ ← →)

Elian Doranf18a8f8e0b5a
diff --git a/apps/client/src/services/keyboard_shortcut_display.spec.ts b/apps/client/src/services/keyboard_shortcut_display.spec.ts
index 44153e11cb..803df2536d 100644
--- a/apps/client/src/services/keyboard_shortcut_display.spec.ts
+++ b/apps/client/src/services/keyboard_shortcut_display.spec.ts
@@ -61,15 +61,19 @@ describe("keyboard_shortcut_display", () => {
expect(formatShortcutKey("Del")).toBe("Delete");
expect(formatShortcutKey("delete")).toBe("Delete");
expect(formatShortcutKey("ESC")).toBe("Esc");
- expect(formatShortcutKey("ArrowUp")).toBe("Up");
- expect(formatShortcutKey("up")).toBe("Up");
expect(formatShortcutKey("PageDown")).toBe("Page Down");
});
- it("renders the plus key (named token or glyph) as '+' and never translates it", () => {
+ it("renders normalization-only keys (arrows, plus) as their universal glyph and never translates them", () => {
+ expect(formatShortcutKey("ArrowUp")).toBe("↑");
+ expect(formatShortcutKey("up")).toBe("↑");
+ expect(formatShortcutKey("Down")).toBe("↓");
+ expect(formatShortcutKey("Left")).toBe("←");
+ expect(formatShortcutKey("Right")).toBe("→");
expect(formatShortcutKey("Plus")).toBe("+");
expect(formatShortcutKey("+")).toBe("+");
- // Normalization-only token: a translator must not be able to override the universal glyph.
+ // A translator must not be able to override a universal glyph.
+ expect(formatShortcutKey("ArrowUp", fakeTranslate)).toBe("↑");
expect(formatShortcutKey("Plus", fakeTranslate)).toBe("+");
});
@@ -83,7 +87,7 @@ describe("keyboard_shortcut_display", () => {
it("uses the translator for known tokens and ignores it for pass-through tokens", () => {
expect(formatShortcutKey("Ctrl", fakeTranslate)).toBe("L·CTRL");
- expect(formatShortcutKey("ArrowLeft", fakeTranslate)).toBe("L·LEFT");
+ expect(formatShortcutKey("Enter", fakeTranslate)).toBe("L·ENTER");
// Letters have no id, so the translator is never consulted.
expect(formatShortcutKey("J", fakeTranslate)).toBe("J");
});
@@ -99,19 +103,21 @@ describe("keyboard_shortcut_display", () => {
describe("formatShortcut", () => {
it("produces an ordered list of English labels by default", () => {
expect(formatShortcut("Ctrl+Shift+J")).toEqual([ "Ctrl", "Shift", "J" ]);
- expect(formatShortcut("Alt+Left")).toEqual([ "Alt", "Left" ]);
+ expect(formatShortcut("Alt+Left")).toEqual([ "Alt", "←" ]);
expect(formatShortcut("Meta+Plus")).toEqual([ "Meta", "+" ]);
expect(formatShortcut("F5")).toEqual([ "F5" ]);
});
- it("translates every table token while leaving pass-through tokens intact", () => {
- expect(formatShortcut("Ctrl+Shift+Up", fakeTranslate)).toEqual([ "L·CTRL", "L·SHIFT", "L·UP" ]);
+ it("translates the translatable tokens while leaving pass-through and glyph tokens intact", () => {
+ expect(formatShortcut("Ctrl+Shift+Enter", fakeTranslate)).toEqual([ "L·CTRL", "L·SHIFT", "L·ENTER" ]);
expect(formatShortcut("Ctrl+J", fakeTranslate)).toEqual([ "L·CTRL", "J" ]);
+ // Arrow glyphs are normalization-only, so a translator leaves them untouched.
+ expect(formatShortcut("Ctrl+Up", fakeTranslate)).toEqual([ "L·CTRL", "↑" ]);
});
it("strips global: and normalizes aliases end-to-end", () => {
expect(formatShortcut("global:CommandOrControl+Alt+P")).toEqual([ "Ctrl", "Alt", "P" ]);
- expect(formatShortcut("Cmd+ArrowRight")).toEqual([ "Meta", "Right" ]);
+ expect(formatShortcut("Cmd+ArrowRight")).toEqual([ "Meta", "→" ]);
});
it("returns [] for an empty shortcut", () => {
diff --git a/apps/client/src/services/keyboard_shortcut_display.ts b/apps/client/src/services/keyboard_shortcut_display.ts
index 3b90216efd..988e42c70b 100644
--- a/apps/client/src/services/keyboard_shortcut_display.ts
+++ b/apps/client/src/services/keyboard_shortcut_display.ts
@@ -140,14 +140,16 @@ const KEY_LABELS: Record<string, { id?: string; en: string }> = {
end: { id: "end", en: "End" },
pageup: { id: "page_up", en: "Page Up" },
pagedown: { id: "page_down", en: "Page Down" },
- up: { id: "up", en: "Up" },
- arrowup: { id: "up", en: "Up" },
- down: { id: "down", en: "Down" },
- arrowdown: { id: "down", en: "Down" },
- left: { id: "left", en: "Left" },
- arrowleft: { id: "left", en: "Left" },
- right: { id: "right", en: "Right" },
- arrowright: { id: "right", en: "Right" },
+ // Arrow keys: the physical keycap is the glyph itself and it reads identically in every language,
+ // so these are normalization-only (no `id`, never translated), like the plus key below.
+ up: { en: "↑" },
+ arrowup: { en: "↑" },
+ down: { en: "↓" },
+ arrowdown: { en: "↓" },
+ left: { en: "←" },
+ arrowleft: { en: "←" },
+ right: { en: "→" },
+ arrowright: { en: "→" },
// The plus key is stored as the named token `Plus`; normalized to the universal "+" glyph. No
// `id`: "+" is language-neutral, so it is never routed through translation.
plus: { en: "+" },
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index b48287962c..fdb1a622f5 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1950,10 +1950,6 @@
"end": "End",
"page_up": "Page Up",
"page_down": "Page Down",
- "up": "Up",
- "down": "Down",
- "left": "Left",
- "right": "Right",
"insert": "Insert"
},
"spellcheck": {
diff --git a/apps/client/src/translations/ro/translation.json b/apps/client/src/translations/ro/translation.json
index 0dfe9d3418..3600eb687a 100644
--- a/apps/client/src/translations/ro/translation.json
+++ b/apps/client/src/translations/ro/translation.json
@@ -2744,10 +2744,6 @@
"end": "End",
"page_up": "Page Up",
"page_down": "Page Down",
- "up": "Sus",
- "down": "Jos",
- "left": "Stânga",
- "right": "Dreapta",
"insert": "Insert"
}
}