Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): keep the wrapped file editor anchored on redo and digit boundaries #10508

ClosedMnigos(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/10508/headopened View on GitHub

Editing a large wrapped file in the Files surface still jumps in two cases that stayed open on #7907 after #10018: pressing Enter when the line count crosses a digit boundary (999 to 1000), and the first Redo after a run of Undos. Both leave the caret off screen.

Both fixes live in the patched @pierre/diffs editor.

  • Digit boundary. The editor asked the virtualizer to drop every measured row height so the wider gutter could be remeasured. The file shrank to single-row estimates under the viewport, and the browser clamped the scroll position before any row could be remeasured. Measured heights now stay in place as estimates across the edit and across width changes. Rendered rows are remeasured by the existing resize path, and off screen rows are remeasured when they render. The width tracking from #10018 is removed for the same reason: an under-estimate moves the viewport, a stale estimate does not.
  • First Redo. Undo removed the trailing row elements from the DOM, but the editor's line element cache kept them. The Redo re-created the row, looked up the detached element, read an offsetTop of 0, and scrolled the caret to the top of the rendered block. Update after merging main (2026-10-07): @pierre/diffs 1.5.2 (#16644) clears the cached row elements on every line-count change, so this half is fixed upstream. The redo test in this PR passes on main's unmodified 1.5.2 patch and stays as a regression test. This PR now carries only the digit-boundary and width changes, ported to the 1.5.2 patch.

Not changed: resizing the panel with the caret mid file can still jump. The browser's scroll anchoring and the virtualizer's own anchor both move the viewport after a native rewrap, which needs a change to the virtualizer's render order. That part of #7907 stays open.

Verification

  • vp test run apps/web/src/components/files/fileEditorVirtualization.test.ts: 28 tests pass. The width and digit-boundary tests now encode the estimate policy. The redo test failed on the 1.3.0 base with translateY(0px); on the 1.5.2 base it passes before and after. The 12 width and digit-boundary tests fail on main's 1.5.2 patch and pass here.
  • Web typecheck and lint on the touched files.
  • Chromium web client, 1280×800, word wrap on, explorer hidden, 419 px editor, same sample files and steps as the retest on #7907. scrollTop/L<caret line> comes from the native shadow-DOM selection.
ScenarioBefore (main)After
Enter at line 999 of 99949188/L999 to 29308/L801, first visible line 994 to 828, caret off screen49188/L999 to 49200/L1000, first visible line stays 994
First Redo after Enter ×15, end, Undo ×852268/L1198 to 40008/L1001, view jumps to line 100152268/L1198 to 52288/L1199, caret visible

Before

Recorded on main today for the #7907 retest (comment).

Before: the digit-boundary Enter and the first Redo jump

Before recording, MP4

After

After: Enter at line 999 keeps line 1000 visible, the first Redo keeps line 1199 visible

After recording, MP4

Screenshots after the boundary Enter and after the first Redo

After the Enter at line 999: caret on line 1000, lines 995 to 1000 in view

After the first Redo: caret on line 1199 at the end of the file

Related to #7907. Implemented with Claude Code (Claude Fable 5).

Note

Keep wrapped file editor anchored on redo and digit boundaries

  • Fixes layout invalidation so partial resets only remove measurements at or after the changed line, preserving earlier row measurements instead of clearing everything
  • Removes cached code-width state and width-change cache invalidation from VirtualizedFile; Editor now removes deleted gutter rows from the line-element cache and always passes the edit start line to document-change invalidation instead of selecting the file start based on line-number digit width
  • Expands the editor test DOM shim to model sibling insertion, detached rows, parent relationships, offset-top calculation, and CSSStyleDeclaration reads/writes
  • Adds test coverage for undo/redo row recreation and caret positioning, line-number digit boundary preservation through undo/redo, and wrapped measurement width reconciliation on resize
  • Risk: generated dist.components.VirtualizedFile and dist.editor.Editor artifacts remove cached code-width state and change layout invalidation to use edit start line — callers relying on full-width cache invalidation on resize or digit-width-based file-start selection will see different measurement retention behavior
Macroscope summarized 5660af3.

Summary by CodeRabbit

  • Bug Fixes
    • Improved virtualized file rendering when documents are edited, resized, hidden, or contain varying line counts.
    • Preserved accurate offscreen content measurements during width changes and updates.
    • Improved editor caret placement after undo and redo operations.
    • Corrected selection and gutter behavior when controlled-selection and line-selection options are enabled.
    • Improved language detection consistency during file rendering.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at f11074d

      Macroscope's review found this PR approvable — This is a narrowly scoped wrapped-editor bug fix with focused regression coverage. Its production impact is limited to measurement invalidation and caret/viewport anchoring in the existing editor path, with no new capability, schema change, deployment change, or static-analysis override.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Review Change Stack

      Important

      Review skipped

      We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Team

      Run ID: bdbcc0d1-0c07-4d36-a69c-ff8ce3b9992b


      📥 Commits

      Reviewing files that changed from the base of the PR and between 8b2838e0e8a73d3fa6476940445c372e47b99db4 and 5660af3959485f6c194600c0baf986bed0c90f96.


      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

      📒 Files selected for processing (2)
      • apps/web/src/components/files/fileEditorVirtualization.test.ts
      • patches/@pierre%2Fdiffs@1.3.0-beta.10.patch

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.



      📝 Walkthrough

      Walkthrough

      Virtualized file layout updates now support partial invalidation, resize reconciliation, and zero-width safeguards. Editor updates synchronize changed documents and stale rows. Renderer updates clean caches, compute languages consistently, and expose additional package entry points.

      Changes

      Virtualized editor behavior

      Layer / File(s)Summary
      Partial layout invalidation and resize handling
      apps/web/src/components/files/fileEditorVirtualization.test.ts, patches/@pierre%2Fdiffs@1.3.0-beta.10.patch
      Virtualized layout updates preserve unaffected measurements, skip zero-width measurement, and expose resize notifications. Tests cover width changes, resize delivery, and hidden-code measurement.
      Editor synchronization and selection behavior
      apps/web/src/components/files/fileEditorVirtualization.test.ts, patches/@pierre%2Fdiffs@1.3.0-beta.10.patch
      Editor updates remove stale rows, synchronize document changes, pass the change start line to layout invalidation, and respect controlled-selection options.
      Line-count and undo/redo regression coverage
      apps/web/src/components/files/fileEditorVirtualization.test.ts
      Test fixtures support rendered rows, offsets, selection, and canvas measurement. Tests cover digit-boundary changes and caret placement after undo and redo.
      Renderer cache cleanup and package exports
      patches/@pierre%2Fdiffs@1.3.0-beta.10.patch
      FileRenderer cleans worker and file-cache state during render-cache updates, computes language before highlighting, and adds public type and utility exports.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Suggested reviewers: juliusmarminge


      Merge Risk: ⚪ Minimal · up to 5660a

      The editor now retains virtualization measurements across relevant edits and width changes and removes stale line elements so redo can locate the recreated caret. The targeted regressions are covered, with no remaining merge-readiness risk identified.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 1 files. (1 skipped: 1 …Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly summarizes the wrapped file editor fixes for redo and line-number digit boundaries.
      Description check✅ PassedThe description explains the problem, changes, and focused verification, and includes before-and-after evidence. It links issue #7907 but does not state explicit maintainer approval or explain why the…

      Full details: Docstring Coverage

      Explanation

      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 1 files. (1 skipped: 1 unsupported.)



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



      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge added labelsmacroscope-review

    5. Note

      Written by claude-opus-5-5 on behalf of Maria

      Hi! We are cleaning up open PRs, and this one appears to have been created with an older model (fable 5). If this change is really important, we recommend rebuilding the PR with a newer model if possible.

    6. maria-rcks closed this

Sign in to join this conversation.