File tree browser keyboard shortcuts conflict with browser native shortcuts (Cmd+L, Ctrl+K, etc.)
Summary
The repository file tree browser's onTreeKeydown handler in tree_list.vue intercepts single-letter key events without checking for modifier keys. This causes browser-native shortcuts like Cmd+L (focus address bar), Ctrl+K (search bar), Ctrl+L, etc. to be swallowed when the file tree has focus.
Reported in #581271 (comment 3133385101).
Root Cause
In app/assets/javascripts/repository/file_tree_browser/components/tree_list.vue, the onTreeKeydown method has an a-z type-ahead handler that matches any single letter keypress without excluding modifier key combos:
// a-z — currently does NOT check for modifier keys
if (/^[a-zA-Z]$/.test(event.key)) {
event.preventDefault(); // This blocks Cmd+L, Ctrl+K, etc.
...
}
When a user presses Cmd+L, event.key is "l" which matches the regex, so event.preventDefault() is called and the browser shortcut is blocked.
Proposed Fix
Add modifier key guards to the a-z handler (and optionally the * handler):
// a-z (only when no modifier keys are pressed)
if (/^[a-zA-Z]$/.test(event.key) && !event.metaKey && !event.ctrlKey && !event.altKey) {
event.preventDefault();
...
}
Alternatively, a top-level early return could be added at the beginning of onTreeKeydown to let all browser/OS shortcuts pass through:
onTreeKeydown(event) {
// Allow all browser/OS shortcuts to pass through
if (event.metaKey || event.ctrlKey) return;
...
}
The per-block guard is more precise if fine-grained control over modifier combos is desired.
Affected File
-
app/assets/javascripts/repository/file_tree_browser/components/tree_list.vue—onTreeKeydownmethod
Steps to Reproduce
- Navigate to any repository page with the file tree browser visible
- Click on any file/directory in the file tree so it has focus
- Press
Cmd+L(macOS) orCtrl+L(Windows/Linux) - Expected: Browser address bar is focused
- Actual: The file tree jumps to a file starting with "L" and the browser shortcut is blocked