fix: preserve Shell tab scroll position across periodic refresh#633
fix: preserve Shell tab scroll position across periodic refresh#633CoderLuii wants to merge 1 commit intositeboon:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated the focusTerminal logic to preserve the terminal's viewport position when focusing. The implementation now saves the current viewport position before focusing and restores it afterward, maintaining view continuity while ensuring the terminal receives focus. Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
problem
the Shell tab resets scroll position to the top every ~1 second. when you scroll up to review output, it snaps back almost immediately.
root cause
the
useEffectinShell.tsx(lines 157-173) callsterminalRef.current?.focus()viarequestAnimationFrameandsetTimeoutwheneverisActive,isConnected, orisInitializedchange. the 1-second settings polling interval triggers React re-renders, which re-fire this effect. xterm.jsfocus()resets the viewport to the cursor position (bottom), losing the user's scroll position.fix
save
buffer.active.viewportYbefore callingfocus(), restore it viascrollToLine()after. this is the same pattern VS Code uses inmarkNavigationAddon.ts.const focusTerminal = () => { - terminalRef.current?.focus(); + const term = terminalRef.current; + if (!term) return; + const savedViewport = term.buffer.active.viewportY; + term.focus(); + term.scrollToLine(savedViewport); };auto-scroll to bottom still works when the user is already at the bottom (default xterm behavior —
focus()moves viewport to cursor,scrollToLinerestores the same position since cursor is at the bottom).Summary by CodeRabbit