-
-
Notifications
You must be signed in to change notification settings - Fork 793
feat(keyboard shortcut): add more Vim-Style Keybind #3498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds Shift+J/Shift+K bindings to rotate the sidebar, adds D/U to scroll half a page via a new scrollHalfPage(direction) function, and refactors scroll keyup cleanup to a named clear function with the listener using { once: true }. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant KS as KeyboardShortcut
participant App as App View
participant SB as Sidebar
rect rgba(200,230,255,0.2)
U->>KS: Press Shift+J
KS->>SB: rotateSidebar(1)
U->>KS: Press Shift+K
KS->>SB: rotateSidebar(-1)
end
rect rgba(200,255,200,0.2)
U->>KS: Press D
KS->>App: scrollHalfPage(1)
KS->>App: focusOnApp() for bounds
U->>KS: Press U
KS->>App: scrollHalfPage(-1)
KS->>App: focusOnApp() for bounds
end
note over KS: Keyup cleanup uses named clear() and listener with { once: true }
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
Extensions/keyboardShortcut.js (3)
47-50
: Reconsider ‘d/u’ semantics; prefer Ctrl+D/Ctrl+U for Vim parity or ignore inputs to avoid hijacking typingIn Vim, half-page is Ctrl+D/Ctrl+U; plain ‘d’/‘u’ are delete/undo. Also, binding plain letters risks capturing typing outside inputs if Mousetrap’s input-ignoring behavior changes.
Option A (Vim-consistent):
- d: { callback: () => scrollHalfPage(1) }, - u: { callback: () => scrollHalfPage(-1) }, + "ctrl+d": { callback: () => scrollHalfPage(1) }, + "ctrl+u": { callback: () => scrollHalfPage(-1) },Option B (keep ‘d/u’, but don’t fire while user is typing):
- d: { callback: () => scrollHalfPage(1) }, - u: { callback: () => scrollHalfPage(-1) }, + d: { callback: (event) => { if (shouldIgnoreKey(event)) return; scrollHalfPage(1); } }, + u: { callback: (event) => { if (shouldIgnoreKey(event)) return; scrollHalfPage(-1); } },Add once (outside this hunk):
function shouldIgnoreKey(event) { const t = event.target; return !!t && ( (t instanceof HTMLInputElement) || (t instanceof HTMLTextAreaElement) || t.isContentEditable === true ); }
128-130
: Good cleanup with once; fix indentation to satisfy BiomeThe named
clear
+{ once: true }
is solid. However, current indentation deviates from file style and triggers the formatter.Apply formatting (tabs, aligned with surrounding code):
- const clear = () => clearInterval(scrollInterval); - document.addEventListener("keyup", clear, { once: true }); + const clear = () => clearInterval(scrollInterval); + document.addEventListener("keyup", clear, { once: true });
126-145
: Biome CI is failing; run formatter or fix indentation in this rangeGitHub Actions reports a Biome formatting failure for 126–145. Run:
biome format Extensions/keyboardShortcut.js
or apply the indentation fix above to clear CI.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
Extensions/keyboardShortcut.js
(4 hunks)
🧰 Additional context used
🪛 GitHub Actions: Code quality
Extensions/keyboardShortcut.js
[error] 126-145: Biome formatting check failed. File 'Extensions/keyboardShortcut.js' content differs from formatting output. Command 'biome ci . --files-ignore-unknown=true --diagnostic-level=error' reported the issue. Run 'biome format Extensions/keyboardShortcut.js' to fix.
🔇 Additional comments (1)
Extensions/keyboardShortcut.js (1)
138-146
: scrollHalfPage implementation is correctBounds clamping and half-page delta are handled correctly.
// Rotate through sidebar items using Shift+J/Shift+K (Vim-style). | ||
"shift+j": { callback: () => rotateSidebar(1) }, | ||
"shift+k": { callback: () => rotateSidebar(-1) }, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shift+J/K bindings look good; safeguard rotateSidebar index to avoid NaN crash
If findActiveIndex
can’t find a match while activeLink
or activePage
exists, it returns undefined
, making findActiveIndex(...) + direction
become NaN
and allItems[index]
will throw. Add a fallback return at the end of findActiveIndex
or coerce in rotateSidebar
.
Add a fallback in findActiveIndex
(outside this hunk):
function findActiveIndex(allItems) {
// ...existing logic...
return -1; // ensure a number is always returned
}
Optionally harden in rotateSidebar
:
const activeIdx = findActiveIndex(allItems);
let index = (typeof activeIdx === "number" ? activeIdx : -1) + direction;
🤖 Prompt for AI Agents
In Extensions/keyboardShortcut.js around lines 35 to 38, the Shift+J/K handlers
call rotateSidebar which relies on findActiveIndex returning a number; if
findActiveIndex returns undefined the index math becomes NaN and accessing
allItems[index] will throw. Modify findActiveIndex (elsewhere in the file) to
always return a number (e.g., return -1 at the end) and additionally harden
rotateSidebar by coercing the result to a numeric fallback before adding
direction (e.g., treat non-number as -1) so index math cannot produce NaN.
Added Vim Inspired Keys
shift+j
,shift+k
: Rotate through sidebard
: Scroll down (half-page)u
: Scroll up (half-page)Summary by CodeRabbit