Skip to content

Add keyboard shortcuts for repository file and code search#36416

Merged
wxiaoguang merged 16 commits intogo-gitea:mainfrom
micahkepe:feature/repo-keyboard-shortcuts
Feb 23, 2026
Merged

Add keyboard shortcuts for repository file and code search#36416
wxiaoguang merged 16 commits intogo-gitea:mainfrom
micahkepe:feature/repo-keyboard-shortcuts

Conversation

@micahkepe
Copy link
Copy Markdown
Contributor

@micahkepe micahkepe commented Jan 21, 2026

Summary

Resolves #36417: Add GitHub-like keyboard shortcuts for repository navigation:

  • Press T to focus the "Go to file" search input
  • Press S to focus the "Search code" input
  • Press Escape to clear and unfocus search inputs

Both search inputs display a keyboard hint (kbd element) showing the available shortcut. The hint hides when the input is focused or has a value.

Screenshots

Screenshot 2026-01-20 at 4 33 27 PM Screenshot 2026-01-20 at 4 33 33 PM

Test Plan

  • Unit tests added in web_src/js/features/repo-shortcuts.test.ts (5 tests)
  • E2E tests added in tests/e2e/repo-shortcuts.test.e2e.ts (6 tests)
  • Manual testing:
    • Navigate to any repository with files
    • Press T → file search input should focus
    • Press S → code search input should focus
    • Press Escape → input should clear and unfocus
    • Verify kbd hints show/hide appropriately

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 21, 2026
@github-actions github-actions bot added modifies/templates This PR modifies the template files modifies/frontend labels Jan 21, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Jan 21, 2026

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.

@micahkepe
Copy link
Copy Markdown
Contributor Author

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

I've refactored to use a declarative approach.

Elements now declare their keyboard shortcuts via data-global-keyboard-shortcut attribute, and a central handler in observer.ts picks them up, similar to the existing data-global-init and data-global-click patterns.

Example:

<input data-global-keyboard-shortcut="s" ...>

Adding new shortcuts now only requires adding the attribute to the element without any JS changes.

@micahkepe micahkepe force-pushed the feature/repo-keyboard-shortcuts branch 2 times, most recently from c3ee89a to 6b95dc0 Compare January 21, 2026 17:45
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Jan 22, 2026

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.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 22, 2026
@silverwind silverwind requested a review from Copilot January 24, 2026 04:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 keydown handler for elements declaring data-global-keyboard-shortcut.
  • Adds code-search hint visibility + Escape handling via a new global init function.
  • Updates repo file search UI to show a T hint 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@micahkepe micahkepe force-pushed the feature/repo-keyboard-shortcuts branch from bb2d4a8 to 7f4493d Compare January 26, 2026 17:16
@lunny lunny added this to the 1.26.0 milestone Jan 26, 2026
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 13, 2026

@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)

@micahkepe
Copy link
Copy Markdown
Contributor Author

micahkepe commented Feb 13, 2026

@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-shortcuts

All 6 repo-shortcuts tests pass on webkit and Mobile Safari. On chromium/Mobile Chrome, the beforeAll login hook times out, but this appears to be a pre-existing issue that also affects the existing example.test.e2e.ts tests (the homepage test fails identically). Not related to this PR.

Details are in tests/e2e/README.md. The Go harness (e2e_test.go) starts a Gitea server with fixtures, then runs npx playwright test against it.

@silverwind
Copy link
Copy Markdown
Member

Ok thanks, I will try that.

@wxiaoguang wxiaoguang removed their assignment Feb 23, 2026
@wxiaoguang wxiaoguang marked this pull request as ready for review February 23, 2026 06:27
@silverwind silverwind self-requested a review February 23, 2026 06:28
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Feb 23, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Feb 23, 2026

Simplified. Now, it only needs the general global-shortcut-wrapper, no special styles are need anymore.

image image

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Feb 23, 2026

Can you retrain the aria-keyshortcuts attribute? Set it via JS maybe? Or maybe even make it work completely off that attribute?

@wxiaoguang
Copy link
Copy Markdown
Contributor

Can you retrain the aria-keyshortcuts attribute? Set it via JS maybe?

image

@silverwind
Copy link
Copy Markdown
Member

Ah okay. And what about the idea making it work completely off that attribute? E.g. no custom attributes?

@wxiaoguang
Copy link
Copy Markdown
Contributor

Ah okay. And what about the idea making it work completely off that attribute? E.g. no custom attributes?

Answer is in code.

image

@wxiaoguang wxiaoguang added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Feb 23, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

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.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 23, 2026
Signed-off-by: silverwind <me@silverwind.io>
@silverwind silverwind self-requested a review February 23, 2026 07:29
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Feb 23, 2026
@silverwind
Copy link
Copy Markdown
Member

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 23, 2026
@wxiaoguang wxiaoguang merged commit 427954b into go-gitea:main Feb 23, 2026
26 checks passed
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 23, 2026
* 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
@micahkepe micahkepe deleted the feature/repo-keyboard-shortcuts branch February 23, 2026 15:12
silverwind added a commit to silverwind/gitea that referenced this pull request Feb 26, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/templates This PR modifies the template files topic/code-linting type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add keyboard shortcuts for repository file and code search

6 participants