Skip to content

fix(editor): preserve combined diff scroll on line focus - #23735

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ci-diff-focus-scroll
Sep 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ci-diff-focus-scroll

Conversation

@nwparker

@nwparker nwparker commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19 $\color{#cf222e}{\Huge{\mathbf{−}}}$​18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

ELI5

Clicking a line in a combined diff should keep the code you were reading in place.

What Changed

Combined diff editors use Monaco's textarea input backend. Its focus handling preserves parent scroll positions; native EditContext focuses a hidden input and can scroll the outer combined view to that input.

The scroll-restoration test now clips its click point to the viewport and verifies that it hits the rendered line. Previously it could click a toolbar or sticky header instead, missing the real focus bug.

Why

With the corrected click, the existing scroll assertion failed three consecutive runs using native EditContext, then passed three consecutive runs with the textarea backend. A separate before/after capture reproduced a 1,238-pixel jump before the fix. Switching the supported input backend is narrower than changing scroll restoration or overriding browser focus methods.

Linked Issue

CI failure: https://github.com/stablyai/orca/actions/runs/36497243185/job/109179890307

Visual Proof

Before: clicking after restoring the deep scroll position jumps back to earlier files.

Before

After: clicking preserves the section being read.

After

Testing

  • macOS hidden Electron: corrected test fails 3/3 before and passes 3/3 after; separate screenshot run confirms both outcomes again.
  • Web typecheck and changed-code quality gate pass.
  • Linux targeted E2E and repository CI pending.

Review

Uses a supported Monaco backend for both editable and read-only combined diffs. Standalone editors, remote protocols, file contents, and test timeouts are unchanged. Combined review surfaces share this editor component.

Agent skill upstream boundary

  • Not applicable.

Checklist

  • Small and focused; behavior, mechanism, and alternative explained.
  • Before/after rendered proof attached.
  • Self-reviewed; cross-platform and SSH/remote impact considered.
  • Local validation above passes; CI covers the remaining checks.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adjusts editor focus behavior in the diff viewer.

The PR appears safe to merge.

Summary

The PR switches combined diff editors to Monaco’s textarea input backend to preserve scroll position on line focus. It also makes the E2E click target check that a rendered line is actually under the pointer.

Reviews (1) · Last reviewed commit: "fix(editor): preserve combined diff scro..."

@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 6b5a8828-409a-40a6-b7b9-c57c0aaf212c

📥 Commits

Reviewing files that changed from the base of the PR and between 64dbe87 and 7e00420.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/DiffSectionBody.tsx
  • tests/e2e/combined-diff-scroll-restore.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The diff editor options now disable Monaco’s native EditContext behavior. The end-to-end test helper now checks each diff line’s visible intersection and skips points obscured by another element. It returns null if it finds no unobscured visible point.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 7e004

This change switches combined diff editors to Monaco's textarea input backend so clicking a line no longer scrolls the outer view. No concrete regression was found. Merge readiness is good once the pending CI checks pass.

🚥 Pre-merge checks | ✅ 4 | ❌ 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving combined diff scroll position when focusing a line.
Description check ✅ Passed The description is complete and focused. It explains the user impact, implementation, rationale, testing evidence, visual proof, scope, and pending CI checks. The linked item is a CI failure rather th…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

Important

Forcing editContext: false moves the editable combined-diff sections onto Monaco's legacy textarea input path, which carries confirmed upstream input regressions (dropped first keystroke over a backward selection; lost Japanese IME reconversion). Details inline — worth confirming this tradeoff is intended.

Reviewed changes

  • Scroll jump fix: DiffSectionBody.tsx now sets editContext: false, so focusing a diff line uses Monaco's textarea backend instead of focusing the hidden native EditContext node that scrolls the shared .combined-diff-scroll-container into view.
  • Test hardening: clickVisibleDiffLine in the combined-diff scroll spec now clips each .view-line rect to the scroll container and hit-tests it with document.elementFromPoint, so a sticky header or toolbar can no longer absorb the click and let the scroll assertion pass without ever focusing the editor.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

keepCurrentModifiedModel
options={{
// Native EditContext focus scrolls its hidden input into the combined viewport.
editContext: false,

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.

Forcing editContext: false fixes the scroll jump, but it also drops every combined diff — including the editable unstaged sections this new test exercises — onto Monaco's legacy textarea input path. On Chromium (this app's Electron runtime) that path has an open upstream bug where the first keystroke over a backward (Shift+Left) selection is swallowed, and it loses EditContext-based Japanese IME reconversion. Please confirm the tradeoff is intended for the editable sections, or consider keeping native EditContext and restoring the container's scrollTop around focus instead.

Technical details
# `editContext: false` regresses input on the editable combined diff

## Affected sites
- `src/renderer/src/components/editor/DiffSectionBody.tsx:170` — sets `editContext: false` for every `DiffSectionBody` editor.
- `src/renderer/src/components/editor/DiffSectionItem.tsx:67` — `isEditable = section.area === 'unstaged'`; `readOnly: !isEditable` (`DiffSectionBody.tsx:171`), so the modified side of an unstaged combined diff is editable.
- `tests/e2e/combined-diff-scroll-restore.spec.ts` — `openCombinedDiff` selects the `unstaged` area, i.e. the editable path, so the spec exercises the affected configuration.

## Why this is introduced here
- monaco-editor 0.55.1 defaults `editContext` to `true` and enables it on Chromium (`node_modules/monaco-editor/esm/vs/editor/common/config/editorOptions.js:3135`, `included: isChrome || isEdge || isNative`), so before this change these editors used the native EditContext backend and these textarea-path defects did not apply.

## Evidence (upstream, against the pinned 0.55.1)
- microsoft/monaco-editor#5448 — typing over a backward selection requires two keypresses on the textarea path; explicit note that "forcing the same path in Chromium with `editContext: false` reproduces it there too".
- microsoft/monaco-editor#5207 — repro is literally `editContext: false`; first keypress is ignored over a backward/RTL selection.
- microsoft/vscode#238643 — turning EditContext off stops reconversion of a selected run of Japanese text via the conversion key.

## Required outcome
- The scroll fix must hold for editable sections while not regressing text input. Either accept the backend tradeoff explicitly, or keep EditContext and neutralise the focus-induced scroll (e.g. save/restore `.combined-diff-scroll-container` `scrollTop` across the focus event).

## Open questions for the human
- Are users expected to actually type into the editable `unstaged` combined diff (vs. read-only branch review), which would make the dropped-keystroke regression user-visible?

@nwparker
nwparker merged commit bd5dca4 into main Sep 29, 2026
43 checks passed
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