Add Cmd+Up/Down keyboard shortcuts for terminal scrolling#2679
Add Cmd+Up/Down keyboard shortcuts for terminal scrolling#2679sawka merged 3 commits intowavetermdev:mainfrom
Conversation
- Cmd+Down: Scroll to bottom of terminal - Cmd+Up: Scroll to top of terminal - Quick navigation for long terminal output 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
WalkthroughAdds multiple keyboard shortcut handlers to Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Areas to double-check:
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)frontend/app/view/term/term-model.ts (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
2247aa6 to
ff44fb3
Compare
frontend/app/view/term/term-model.ts
Outdated
| if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowDown")) { | ||
| // Scroll to bottom | ||
| if (this.termRef?.current?.terminal) { | ||
| this.termRef.current.terminal.scrollToBottom(); | ||
| } | ||
| return true; | ||
| } | ||
| if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowUp")) { | ||
| // Scroll to top | ||
| if (this.termRef?.current?.terminal) { | ||
| this.termRef.current.terminal.scrollToLine(0); | ||
| } | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Only consume Cmd+ArrowUp/Down when a terminal instance actually exists
Right now these branches return true even if this.termRef?.current?.terminal is falsy. In vdom mode or before the terminal mounts, that means Cmd+ArrowUp/Down are swallowed and never reach the vdom key handler or app-level handlers, which goes against the goal of “not interfering with other shortcuts.”
Recommend only returning true when a terminal is present and we actually scroll; otherwise let the event fall through:
- if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowDown")) {
- // Scroll to bottom
- if (this.termRef?.current?.terminal) {
- this.termRef.current.terminal.scrollToBottom();
- }
- return true;
- }
- if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
- // Scroll to top
- if (this.termRef?.current?.terminal) {
- this.termRef.current.terminal.scrollToLine(0);
- }
- return true;
- }
+ if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowDown")) {
+ const terminal = this.termRef?.current?.terminal;
+ if (terminal) {
+ // Scroll to bottom
+ terminal.scrollToBottom();
+ return true;
+ }
+ return false;
+ }
+ if (keyutil.checkKeyPressed(waveEvent, "Cmd:ArrowUp")) {
+ const terminal = this.termRef?.current?.terminal;
+ if (terminal) {
+ // Scroll to top
+ terminal.scrollToLine(0);
+ return true;
+ }
+ return false;
+ }This keeps the new shortcuts effective on terminal blocks while avoiding unintended interception when there is no terminal to scroll.
🤖 Prompt for AI Agents
In frontend/app/view/term/term-model.ts around lines 492 to 505, the
Cmd+ArrowUp/Down handlers currently return true even when
this.termRef?.current?.terminal is falsy, causing the key event to be swallowed
when no terminal instance exists; change the logic so you only return true after
confirming a terminal exists and you actually call
scrollToBottom()/scrollToLine(0) — i.e., check for
this.termRef?.current?.terminal, perform the scroll, then return true; otherwise
do not return true so the event falls through to vdom or app-level handlers.
|
@stevenvo I did some research here, and it isn't safe to bind Cmd+Up/Down (which ends up mapping to Alt+Up/Down) in the terminal. This can conflict with terminal apps like So, I looked into what native MacOS and Linux/Windows terminals use. And it turns out to be: Shift:PageUp/Down, and Shift:Home/End which controls scrollback. On MacOS you can get these by using Fn:Shift:Arrows (Fn:Shift:ArrowLeft is Shift:Home, Fn:Shift:ArrowUp is Shift:PageUp, etc). These now mirror iterm2 and terminals like gnome terminal etc and so are safe to add. |
Summary
Adds keyboard shortcuts for quick navigation in terminal output.
Shortcuts
Use Cases
Implementation
Test Plan
🤖 Generated with Claude Code