feat(ui): add global and context-aware keyboard shortcuts - #38629
feat(ui): add global and context-aware keyboard shortcuts#38629SudhanshuMatrix wants to merge 1 commit into
Conversation
ea5c385 to
b80742e
Compare
| </div> | ||
| </footer> | ||
|
|
||
| {{template "base/keyboard_shortcuts_modal" .}} |
There was a problem hiding this comment.
It can't be right to flood such a large template into every page. It isn't used for more than >99% time.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks for the clarification @delvh once @wxiaoguang gives it a go I will the update the PR
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // Handle specific page shortcuts | ||
| if (key === 'w') { | ||
| const branchDropdown = document.querySelector<HTMLElement>('.branch-dropdown-button'); | ||
| if (branchDropdown) { | ||
| e.preventDefault(); | ||
| branchDropdown.click(); | ||
| return; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks for the review I have updated the PR to address this
447eddc to
4d8c320
Compare
… in JS Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com>
4d8c320 to
16a4fa1
Compare
|
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 |
|
My overall thought on the UI is that fomantic modal look dated and should be replaced with something better (likely 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. |
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
?to view all available shortcuts for the current page context. PressEscto close it.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 Dashboardg c: Go to Codes: Focus Search boxw: Open Branch/Tag switchert: Activate File Findery: Expand URL to permanent commit hash (Permalink)b: Toggle Git Blame viewTechnical Details
shortcut.ts.keyboard_shortcuts_modal.tmplincluded in the base footer, reusing Gitea's native.ui.modalCSS components.web_src/css/modules/shortcut.css.shortcut.tsto fully comply with Gitea's strict Content Security Policy (script-src 'self'), removing all inlineonclickattributes.getRepoLink()DOM inspector inshortcut.tsguarantees robust repository routing context across all views.shortcut.tsto ensure shortcuts do not trigger while typing in inputs, textareas, or contenteditable elements.Screenshot