detached 677e3c0

refactor: simplify key capture switch statement

commit
677e3c0376ec2346e50e27ef87ee4ee3da5a4d04
author
brice · · 2026-01-24 16:34 UTC
parent
026a7ae
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +12 -35
M webui/src/pages/config/KeyCaptureModal.svelte +12 -35
@@ -46,43 +46,20 @@
4646 if (e.ctrlKey) parts.push("ctrl");
4747 if (e.altKey) parts.push("alt");
4848
49- let key = e.key.toLowerCase();
50- switch (key) {
51- case "control":
52- case "alt":
53- case "shift":
54- case "meta":
55- return; // Modifier only, wait for actual key
56- case "arrowleft":
57- key = "arrowleft";
58- break;
59- case "arrowright":
60- key = "arrowright";
61- break;
62- case "arrowup":
63- key = "arrowup";
64- break;
65- case "arrowdown":
66- key = "arrowdown";
67- break;
68- case "escape":
69- // Escape closes the modal entirely
70- onCancel();
71- return;
72- case " ":
73- key = "space";
74- break;
75- case "enter":
76- key = "enter";
77- break;
78- case "tab":
79- key = "tab";
80- break;
81- case "backspace":
82- key = "backspace";
83- break;
49+ // Ignore modifier-only presses
50+ if (["control", "alt", "shift", "meta"].includes(e.key.toLowerCase())) {
51+ return;
8452 }
8553
54+ // Escape closes the modal
55+ if (e.key === "Escape") {
56+ onCancel();
57+ return;
58+ }
59+
60+ // Normalize key name
61+ const key = e.key === " " ? "space" : e.key.toLowerCase();
62+
8663 // Only add shift modifier for letter keys and non-symbol keys
8764 // Symbol keys like { } + etc. are already the shifted result
8865 if (e.shiftKey && !SHIFTED_SYMBOLS.has(e.key)) {
@@ -46,43 +46,20 @@
46 if (e.ctrlKey) parts.push("ctrl");46 if (e.ctrlKey) parts.push("ctrl");
47 if (e.altKey) parts.push("alt");47 if (e.altKey) parts.push("alt");
48 48
49- let key = e.key.toLowerCase();49+ // Ignore modifier-only presses
50- switch (key) {50+ if (["control", "alt", "shift", "meta"].includes(e.key.toLowerCase())) {
51- case "control":51+ return;
52- case "alt":
53- case "shift":
54- case "meta":
55- return; // Modifier only, wait for actual key
56- case "arrowleft":
57- key = "arrowleft";
58- break;
59- case "arrowright":
60- key = "arrowright";
61- break;
62- case "arrowup":
63- key = "arrowup";
64- break;
65- case "arrowdown":
66- key = "arrowdown";
67- break;
68- case "escape":
69- // Escape closes the modal entirely
70- onCancel();
71- return;
72- case " ":
73- key = "space";
74- break;
75- case "enter":
76- key = "enter";
77- break;
78- case "tab":
79- key = "tab";
80- break;
81- case "backspace":
82- key = "backspace";
83- break;
84 }52 }
85 53
54+ // Escape closes the modal
55+ if (e.key === "Escape") {
56+ onCancel();
57+ return;
58+ }
59+
60+ // Normalize key name
61+ const key = e.key === " " ? "space" : e.key.toLowerCase();
62+
86 // Only add shift modifier for letter keys and non-symbol keys63 // Only add shift modifier for letter keys and non-symbol keys
87 // Symbol keys like { } + etc. are already the shifted result64 // Symbol keys like { } + etc. are already the shifted result
88 if (e.shiftKey && !SHIFTED_SYMBOLS.has(e.key)) {65 if (e.shiftKey && !SHIFTED_SYMBOLS.has(e.key)) {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close