Skip to content

Fix terminal scroll intent across workspace switches - #6319

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/terminal-scroll-intent-design
Jun 25, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/terminal-scroll-intent-design

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add an explicit terminal scroll intent model for follow-output vs pinned viewport
  • enforce intent at output write, fit, visibility resume, and hidden snapshot replay boundaries
  • stop using xterm onScroll as authoritative user intent
  • add a dedicated viewport-sampling e2e repro for worktree switches and split oversized touched files for lint compliance

Verification

  • pnpm exec oxlint src/renderer/src/lib/pane-manager/pane-lifecycle.ts src/renderer/src/lib/pane-manager/pane-dom-creation.ts src/renderer/src/lib/pane-manager/terminal-scroll-intent.ts src/renderer/src/lib/pane-manager/terminal-scroll-intent.test.ts tests/e2e/terminal-long-table-scroll-restore.spec.ts tests/e2e/terminal-pinned-viewport-worktree-switch.spec.ts tests/e2e/terminal-long-table-fixtures.ts
  • pnpm run typecheck:web
  • pnpm test src/renderer/src/lib/pane-manager/terminal-scroll-intent.test.ts src/renderer/src/lib/pane-manager/pane-tree-ops.test.ts src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.test.ts src/renderer/src/components/terminal-pane/use-terminal-scroll-visibility-memory.test.ts src/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • npx playwright test tests/e2e/terminal-pinned-viewport-worktree-switch.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1
  • npx playwright test tests/e2e/terminal-long-table-scroll-restore.spec.ts --config tests/playwright.config.ts --project electron-headless --workers=1

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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: fc8028a1-c833-4bc1-ace6-7e2e53fe7b01

📥 Commits

Reviewing files that changed from the base of the PR and between 2d42393 and 18941f7.

📒 Files selected for processing (6)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/use-terminal-scroll-visibility-memory.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-scroll-visibility-memory.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/terminal-scroll-intent.test.ts
  • src/renderer/src/lib/pane-manager/terminal-scroll-intent.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/terminal-scroll-intent.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/use-terminal-scroll-visibility-memory.ts

📝 Walkthrough

Walkthrough

The PR adds a terminal scroll-intent architecture spec and a new scroll-intent module with unit tests. It wires scroll-intent tracking into pane creation, keyboard and pointer scrolling, output writes, fit/resume paths, and snapshot replay. It also moves long-table e2e fixtures into a shared helper and adds e2e coverage for pinned viewport behavior during worktree switching.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes Summary and Verification, but it omits required Screenshots, AI Review Report, Security Audit, and Notes sections. Add the missing template sections and fill in the testing checklist, AI review report, security audit, and notes with concrete details.
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: explicit terminal scroll intent handling across workspace switches.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/terminal-pane/terminal-visibility-resume.ts (1)

46-50: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale comment: restore path was replaced by intent enforcement.

The comment still explains a content-matching-free restore of numeric viewport positions, but resume now enforces scroll intent via enforceTerminalViewportIntents and the captureViewportPositions(!wasVisible) return value is discarded. The call is now retained only for its snapshot/epoch side effect — please update the comment to reflect that so the discarded return value doesn't read as a mistake.

🧹 Nitpick comments (3)
tests/e2e/terminal-long-table-fixtures.ts (1)

77-80: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: extract the duplicated writeStdout template helper.

The same writeStdout async helper is inlined in longMarkdownTableScript (Lines 77-80), emojiFixtureMarkdownTableScript (Lines 199-202), narrowSignerMarkdownTableScript (Lines 240-243), and again in scrollbackFixtureScript in terminal-pinned-viewport-worktree-switch.spec.ts. A shared writeStdoutSnippet string constant would keep the win32 flush delay consistent in one place.

tests/e2e/terminal-pinned-viewport-worktree-switch.spec.ts (1)

147-152: 🎯 Functional Correctness | 🔵 Trivial

Add a comment explaining the necessity of the large charLimit argument.

The second argument 30_000 is correctly passed as charLimit (not a timeout), but the value significantly exceeds the function's default of 4000. Add a brief inline note or local comment justifying why such a large buffer capture is required (e.g., "Ensures scrollback capacity to catch the DONE marker after viewport switch") to prevent future confusion regarding this hard-coded threshold.

src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.ts (1)

607-621: 📐 Maintainability & Code Quality | 🔵 Trivial

Document the terminal.write.length < 2 arity branch.

The terminal.write.length check detects if the target supports the optional parse-completion callback. Verified: @xterm/xterm defines write(data, callback?), so write.length is 2 only when the callback is expected. This branch distinguishes standard async xterm handles (requiring the callback path) from mock or callback-less targets that settle synchronously. Add an inline comment explaining this non-obvious intent detection.

📝 Suggested fix
   const scrollIntent = captureTerminalWriteScrollIntent(terminal)
   if (!scrollIntent) {
     terminal.write(data)
     return
   }
+  // xterm's write(data, cb) parses asynchronously, so intent enforcement
+  // must wait for the callback. Callback-less targets (arity < 2) settle
+  // immediately, allowing inline enforcement.
   if (terminal.write.length < 2) {
     terminal.write(data)
     enforceTerminalWriteScrollIntent(terminal, scrollIntent)
     return
   }

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bea9860b-0fa7-46c4-9ebd-aa9d0fa40e8e

📥 Commits

Reviewing files that changed from the base of the PR and between 634a1b2 and 2d42393.

📒 Files selected for processing (18)
  • docs/terminal-scroll-intent-architecture.md
  • src/renderer/src/components/terminal-pane/keyboard-handlers.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-visibility-resume.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/renderer/src/components/terminal-pane/use-terminal-scroll-visibility-memory.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
  • src/renderer/src/lib/pane-manager/pane-terminal-output-scheduler.ts
  • src/renderer/src/lib/pane-manager/pane-tree-ops.ts
  • src/renderer/src/lib/pane-manager/terminal-scroll-intent.test.ts
  • src/renderer/src/lib/pane-manager/terminal-scroll-intent.ts
  • tests/e2e/terminal-long-table-fixtures.ts
  • tests/e2e/terminal-long-table-scroll-restore.spec.ts
  • tests/e2e/terminal-pinned-viewport-worktree-switch.spec.ts

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Follow-up after live repro reports:

  • Root cause addressed here: pinned scroll intent was still tied to the transient xterm instance/state. During worktree switch/remount/replay, a terminal can briefly report an empty or shorter buffer (baseY: 0) or bottom state, which overwrote the user's pinned viewport as followOutput.
  • Fix: bind scroll intent to the durable pane leafId, reuse it across remounted xterm instances, and ignore shorter-history samples while a pinned intent is stored. Also guarded pending focus catch-up so it cannot force a pinned terminal to bottom.
  • Added regression coverage for a remounted empty terminal preserving the pane-keyed pinned viewport.

Validation run locally:

  • pnpm run typecheck:web
  • pnpm test src/renderer/src/components/terminal-pane/use-terminal-scroll-visibility-memory.test.ts src/renderer/src/lib/pane-manager/terminal-scroll-intent.test.ts src/renderer/src/components/terminal-pane/use-terminal-pane-global-effects.test.ts src/renderer/src/lib/pane-manager/pane-scroll.test.ts src/renderer/src/lib/pane-manager/pane-split-scroll.test.ts
  • pnpm run test:e2e -- tests/e2e/terminal-pinned-viewport-worktree-switch.spec.ts
  • pnpm run test:e2e -- tests/e2e/terminal-long-table-scroll-restore.spec.ts
  • Live CDP check against the running dev Electron renderer on port 9525: pinned the available top TUI-like pane at viewportY/baseY = 133/139, switched away/back 5 times, sampled return frames; min/max viewport stayed 133 with zero top, bottom, or off-target samples.

Note: the running dev profile did not contain the named scroll-primary / scroll-secondary worktrees, so the live check used the active claude-fullscreen-tui-scroll worktree and switched to terminal-scroll-top.

@Jinwoo-H
Jinwoo-H merged commit cd1d4df into main Jun 25, 2026
3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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