Skip to content

Conversation

@micahkepe
Copy link

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

…earch

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 blur focused 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.

Includes unit tests and e2e tests for the new functionality.
…tcuts

Instead of having JavaScript code guess which elements exist on a page,
elements now declare their keyboard shortcuts via data-global-keyboard-shortcut
attribute. This makes it easier to add new shortcuts and follows Gitea's
existing patterns for data-global-init and data-global-click.
- Use `target.isContentEditable` instead of `[contenteditable="true"]` selector
  to properly detect all contenteditable elements
- Use `CSS.escape()` for keyboard shortcut key to handle special characters
- Rename scoped CSS class to `.repo-file-search-shortcut-hint` to avoid
  conflict with global `.repo-search-shortcut-hint` styles
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/frontend modifies/templates This PR modifies the template files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add keyboard shortcuts for repository file and code search

5 participants