Skip to content

fix: preserve Shell tab scroll position across periodic refresh#633

Open
CoderLuii wants to merge 1 commit intositeboon:mainfrom
CoderLuii:fix/shell-tab-scroll-reset
Open

fix: preserve Shell tab scroll position across periodic refresh#633
CoderLuii wants to merge 1 commit intositeboon:mainfrom
CoderLuii:fix/shell-tab-scroll-reset

Conversation

@CoderLuii
Copy link
Copy Markdown

@CoderLuii CoderLuii commented Apr 10, 2026

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 useEffect in Shell.tsx (lines 157-173) calls terminalRef.current?.focus() via requestAnimationFrame and setTimeout whenever isActive, isConnected, or isInitialized change. the 1-second settings polling interval triggers React re-renders, which re-fire this effect. xterm.js focus() resets the viewport to the cursor position (bottom), losing the user's scroll position.

fix

save buffer.active.viewportY before calling focus(), restore it via scrollToLine() after. this is the same pattern VS Code uses in markNavigationAddon.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, scrollToLine restores the same position since cursor is at the bottom).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed terminal focus behavior to preserve the current viewport position, preventing accidental scrolling when the terminal regains focus.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e37ac5f3-da22-4994-9965-52528f17ef7b

📥 Commits

Reviewing files that changed from the base of the PR and between 388134c and b61736c.

📒 Files selected for processing (1)
  • src/components/shell/view/Shell.tsx

📝 Walkthrough

Walkthrough

Updated 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

Cohort / File(s) Summary
Terminal Focus Viewport Preservation
src/components/shell/view/Shell.tsx
Modified the focusTerminal effect to capture the current viewport position before focusing, then restore it after. Focus scheduling via requestAnimationFrame and setTimeout remains unchanged.

Poem

🐰 The terminal now holds its view so tight,
When focus arrives, the viewport stays in sight,
No more jumping scrolls or vanished lines,
Just smooth refocus—a rabbit-approved design! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: preserve Shell tab scroll position across periodic refresh' directly and accurately describes the main change: preserving scroll position in the Shell tab during periodic refreshes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant