Add keyboard shortcuts for repository file and code search#36416
Add keyboard shortcuts for repository file and code search#36416wxiaoguang merged 16 commits intogo-gitea:mainfrom
Conversation
|
It needs to make the elements declare what keyboard shortcut they support, but not let the code to guess which element is on current page. Otherwise it will be very difficult to support more, ref : #5796 Update: some maintainers have discussed in #5796 a lot, they might have some ideas and can provide more inputs. |
I've refactored to use a declarative approach. Elements now declare their keyboard shortcuts via Example: <input data-global-keyboard-shortcut="s" ...>Adding new shortcuts now only requires adding the attribute to the element without any JS changes. |
c3ee89a to
6b95dc0
Compare
|
Thanks. Note that E2E tests currently don't execute as part of the CI. We should fix that eventually but until then it's best if another contributor can run them locally to confirm they work. |
There was a problem hiding this comment.
Pull request overview
Adds GitHub-like keyboard shortcuts for repository navigation/search (focus “Go to file” with T, focus “Search code” with S, and clear/unfocus via Escape), plus UI hints to advertise the shortcuts.
Changes:
- Introduces a global
keydownhandler for elements declaringdata-global-keyboard-shortcut. - Adds code-search hint visibility +
Escapehandling via a new global init function. - Updates repo file search UI to show a
Thint and blur/clear behavior, with accompanying unit + E2E tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| web_src/js/modules/observer.ts | Adds global keyboard shortcut dispatch based on data-global-keyboard-shortcut. |
| web_src/js/index-domready.ts | Registers repo shortcut init function during app init. |
| web_src/js/features/repo-shortcuts.ts | Adds code-search hint/escape behavior via data-global-init. |
| web_src/js/features/repo-shortcuts.test.ts | Unit tests for code-search hint visibility and Escape behavior. |
| web_src/js/components/RepoFileSearch.vue | Adds T shortcut attribute, hint rendering, and blur-on-escape behavior. |
| web_src/css/repo.css | Adds styling for shortcut hints and wrapper positioning/overrides. |
| tests/e2e/repo-shortcuts.test.e2e.ts | Playwright coverage for focusing inputs and hint show/hide behavior. |
| templates/repo/home_sidebar_top.tmpl | Adds code search shortcut attribute, hint element, and wrapper class. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fb1bab4 to
7f14c0a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bb2d4a8 to
7f4493d
Compare
|
@micahkepe how are you running those e2e tests? Which commands? (It might sound like a strange question but I have ignored the "demo" e2e tests that exist in the repo so far. I plan to fix them up soon, but any pointers woul be much appreciated) |
I ran them with: make playwright
make test-e2e-sqlite#repo-shortcutsAll 6 repo-shortcuts tests pass on webkit and Mobile Safari. On chromium/Mobile Chrome, the Details are in |
|
Ok thanks, I will try that. |
|
Can you retrain the |
|
|
Ah okay. And what about the idea making it work completely off that attribute? E.g. no custom attributes? |
|
By the way, the unit test is not right, it doesn't really test. I have changed the implementation a lot, the unit test still passes. |
Signed-off-by: silverwind <me@silverwind.io>
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
* giteaofficial/main: (81 commits) Add keyboard shortcuts for repository file and code search (go-gitea#36416) Refactor text utility classes to Tailwind CSS (go-gitea#36703) Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660) Fix force push time-line commit comments of pull request (go-gitea#36653) Fix get release draft permission check (go-gitea#36659) Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256) Update JS and PY deps (go-gitea#36708) Move jobparser from act repository to Gitea (go-gitea#36699) Fix push time bug (go-gitea#36693) Add icon to buttons "Close with Comment", "Close Pull Request", "Close Issue" (go-gitea#36654) various fixes (go-gitea#36697) Add AI Contribution Policy to CONTRIBUTING.md (go-gitea#36651) Add some validation on values provided to USER_DISABLED_FEATURES and EXTERNAL_USER_DISABLED_FEATURES (go-gitea#36688) Rework e2e tests (go-gitea#36634) Remove unused functions (go-gitea#36672) Add migration http transport for push/sync mirror lfs (go-gitea#36665) Fix track time issue id (go-gitea#36664) Refactor inline style attributes (go-gitea#36652) Update Nix flake (go-gitea#36679) Upgrade gogit to 5.16.5 (go-gitea#36680) ... # Conflicts: # web_src/js/features/repo-issue-content.ts
* main: (24 commits) Instance-wide (global) info banner and maintenance mode (go-gitea#36571) Add created_by filter to SearchIssues (go-gitea#36670) Inline and lazy-load EasyMDE CSS, fix border colors (go-gitea#36714) Fix release draft access check logic (go-gitea#36720) Change image transparency grid to CSS (go-gitea#36711) Avoid opening new tab when downloading actions logs (go-gitea#36740) Add validation constraints for repository creation fields (go-gitea#36671) Fix SVG height calculation in diff viewer (go-gitea#36748) Fix path resolving (go-gitea#36734) [skip ci] Updated translations via Crowdin Fix track time list permission check (go-gitea#36662) Fix incorrect setting loading order (go-gitea#36735) Use case-insensitive matching for Git error "Not a valid object name" (go-gitea#36728) feat: Add workflow dependencies visualization (go-gitea#36248) Add keyboard shortcuts for repository file and code search (go-gitea#36416) Refactor text utility classes to Tailwind CSS (go-gitea#36703) Prevent redirect bypasses via backslash-encoded paths (go-gitea#36660) Fix force push time-line commit comments of pull request (go-gitea#36653) Fix get release draft permission check (go-gitea#36659) Move `X_FRAME_OPTIONS` setting from `cors` to `security` section (go-gitea#30256) ... # Conflicts: # web_src/css/base.css # web_src/css/index.css




Summary
Resolves #36417: Add GitHub-like keyboard shortcuts for repository navigation:
Tto focus the "Go to file" search inputSto focus the "Search code" inputEscapeto clear and unfocus search inputsBoth search inputs display a keyboard hint (
kbdelement) showing the available shortcut. The hint hides when the input is focused or has a value.Screenshots
Test Plan
web_src/js/features/repo-shortcuts.test.ts(5 tests)tests/e2e/repo-shortcuts.test.e2e.ts(6 tests)T→ file search input should focusS→ code search input should focusEscape→ input should clear and unfocus