Skip to content

feat(ui): add global and context-aware keyboard shortcuts - #38629

Draft
SudhanshuMatrix wants to merge 1 commit into
go-gitea:mainfrom
SudhanshuMatrix:feature/github-style-keyboard-shortcuts
Draft

feat(ui): add global and context-aware keyboard shortcuts#38629
SudhanshuMatrix wants to merge 1 commit into
go-gitea:mainfrom
SudhanshuMatrix:feature/github-style-keyboard-shortcuts

Conversation

@SudhanshuMatrix

@SudhanshuMatrix SudhanshuMatrix commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

This PR standardizes keyboard navigation shortcuts in Gitea's UI to build strong muscle memory and improve power-user workflow.

Pressing ? on any page opens a responsive help modal listing the available shortcuts. The modal and the shortcuts themselves are completely context-aware and will only be active/visible when they are relevant to the current page.

Features

  • Help Modal: Press ? to view all available shortcuts for the current page context. Press Esc to close it.
  • Global Navigation:
    • g i: Go to Issues (context-aware: repository issues vs. global issues)
    • g p: Go to Pull Requests (context-aware: repository pulls vs. global pulls)
    • g d: Go to Dashboard
  • Repository Context:
    • g c: Go to Code
    • s: Focus Search box
    • w: Open Branch/Tag switcher
    • t: Activate File Finder
  • File View Context:
    • y: Expand URL to permanent commit hash (Permalink)
    • b: Toggle Git Blame view

Technical Details

  • Extends the existing shortcut framework in shortcut.ts.
  • Implements keyboard_shortcuts_modal.tmpl included in the base footer, reusing Gitea's native .ui.modal CSS components.
  • Modularized styling placed in web_src/css/modules/shortcut.css.
  • Event handlers are attached dynamically in shortcut.ts to fully comply with Gitea's strict Content Security Policy (script-src 'self'), removing all inline onclick attributes.
  • Smart getRepoLink() DOM inspector in shortcut.ts guarantees robust repository routing context across all views.
  • Failsafes built into shortcut.ts to ensure shortcuts do not trigger while typing in inputs, textareas, or contenteditable elements.

Screenshot

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 25, 2026
@github-actions github-actions Bot added topic/ui Change the appearance of the Gitea UI type/feature Completely new functionality. Can only be merged if feature freeze is not active. labels Jul 25, 2026
@SudhanshuMatrix
SudhanshuMatrix force-pushed the feature/github-style-keyboard-shortcuts branch from ea5c385 to b80742e Compare July 25, 2026 14:29
@SudhanshuMatrix
SudhanshuMatrix marked this pull request as draft July 25, 2026 14:29
@SudhanshuMatrix
SudhanshuMatrix marked this pull request as ready for review July 25, 2026 14:32
Comment thread templates/base/footer_content.tmpl Outdated
</div>
</footer>

{{template "base/keyboard_shortcuts_modal" .}}

@wxiaoguang wxiaoguang Jul 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It can't be right to flood such a large template into every page. It isn't used for more than >99% time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GitHub does show it on every page, so I was just trying to mimic that behavior. Appreciate the suggestion. Which pages do you think it makes sense to limit it to?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think @wxiaoguang meant that there should be one call to setup this keyboard shortcut thingy.
Not one per template.

I don't think he meant limiting it to certain pages.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification @delvh once @wxiaoguang gives it a go I will the update the PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's quite complicated, and there could be different approaches.

The basic principle is: don't render unnecessary (unused) content into every page. The help dialog can be shown on every page, but it doesn't mean every page should have the HTML code generated for every request.

To show a help dialog, maybe you can use a fetch request to get the content dynamically, maybe you need to collect the supported shortcuts on the current page, etc. You can also learn from other web applications, design the UI/UX with a clean and maintainable approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @wxiaoguang I have Updated the PR I removed the server-side modal template to keep page loads lightweight, and instead made JavaScript dynamically scan the page for active shortcuts and generate the help modal in browser memory only when requested.

Comment thread web_src/js/modules/shortcut.ts Outdated
Comment on lines +156 to +163
// Handle specific page shortcuts
if (key === 'w') {
const branchDropdown = document.querySelector<HTMLElement>('.branch-dropdown-button');
if (branchDropdown) {
e.preventDefault();
branchDropdown.click();
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should never just keep copying&pasting the code.

You should add the shortcut to the element directly, let the framework handle the cases, but not make this file know everything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review I have updated the PR to address this

@wxiaoguang
wxiaoguang marked this pull request as draft July 25, 2026 14:47
@SudhanshuMatrix
SudhanshuMatrix force-pushed the feature/github-style-keyboard-shortcuts branch from 447eddc to 4d8c320 Compare July 27, 2026 04:35
… in JS

Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com>
@SudhanshuMatrix
SudhanshuMatrix force-pushed the feature/github-style-keyboard-shortcuts branch from 4d8c320 to 16a4fa1 Compare July 27, 2026 04:40
@SudhanshuMatrix

Copy link
Copy Markdown
Contributor Author

Hi @silverwind, sorry for the ping. If you have a few minutes, I'd really appreciate your thoughts on this new UI whenever you have the time. Thanks

@silverwind

silverwind commented Jul 29, 2026

Copy link
Copy Markdown
Member

My overall thought on the UI is that fomantic modal look dated and should be replaced with something better (likely <dialog> based modal), but that's a big refactor and out of scope here.

Generally I do think gitea needs global shortcuts but care needs to be taken that it does not interfere with the other existing shortcut mechanisms, e.g. it needs a clean architecture.

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

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. topic/ui Change the appearance of the Gitea UI 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.

5 participants