Skip to content

[diffs/editor] Fix diff rerener in edit mode#878

Open
ije wants to merge 30 commits into
beta-1.3from
editor/diff-render
Open

[diffs/editor] Fix diff rerener in edit mode#878
ije wants to merge 30 commits into
beta-1.3from
editor/diff-render

Conversation

@ije

@ije ije commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Fixes diff re-rendering while the editor is active. Edits were causing jitter, broken caret/selection rendering, incorrect scroll positioning, and stale unified-diff rows because refresh logic, render-range bookkeeping, and document-boundary handling did not account for how diff views virtualize and recompute hunks.

Rendering & refresh

  • Split unified and split refresh paths (refreshUnifiedDiffView / refreshSplitDiffView) and debounce both at 250ms after edits.
  • Unified edits now refresh row spans, hunk separators, and manager state — not just gutter/content HTML.
  • applyDocumentChange updates diff metadata in place instead of forcing a full re-render on every keystroke.

Editor state & cache

  • Remove the rerenderFromDocument / DOM-divergence path. The editor now defaults cacheKey to the file name (or prevName->name for renames) so editing state survives scroll-driven partial re-renders without walking the DOM. @necolas
  • isLineVisible checks for a rendered line element instead of relying on renderRange, which broke caret/selection overlays in virtualized diffs.
  • Defer caret scrollIntoView to the next animation frame to reduce scroll jitter when adding/removing lines.
  • Fix moveCursorToDocEnd / getDocumentBoundarySelection for diff documents with trailing blank lines, no final newline, or a single-line buffer.

Virtualization & hunk recompute

  • Add getLayoutLineCount so render-range clamping uses the live diff size even when layout checkpoints are stale after edits.
  • Preserve renderRange across in-edit layout resets; recompute buffer spacers when the document grows below the rendered window.
  • Add recomputeDiffHunksForEdit with top-aligned addition sentinels so delete-all / sparse-blank edits keep editable rows at the top of split view and retain a caret host row for empty documents.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jun 30, 2026 2:32pm
pierre-docs-diffshub Ready Ready Preview Jun 30, 2026 2:32pm
pierre-docs-trees Ready Ready Preview Jun 30, 2026 2:32pm
pierrejs-diff-demo Ready Ready Preview Jun 30, 2026 2:32pm

Request Review

@ije ije force-pushed the editor/diff-render branch from 9c13b5a to c083d77 Compare June 24, 2026 10:28
@ije ije force-pushed the editor/diff-render branch from c5c0f9a to a256c77 Compare June 24, 2026 14:22
@ije ije requested a review from necolas June 24, 2026 14:27
@ije ije marked this pull request as ready for review June 24, 2026 14:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a256c77517

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/diffs/src/editor/selection.ts Outdated
Comment on lines 1375 to 1378
const line = atEnd
? textDocument.lineCount - (endNewLineTrimmed === true ? 2 : 1)
: 0;
const character = atEnd ? textDocument.getLineLength(line) : 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clamp diff doc-end selection to a valid last line

When editing a diff whose addition document does not have the extra trailing blank line (for example a one-line/no-final-newline file, or after deleting the edit buffer down to empty), passing endNewLineTrimmed=true makes line become -1 for lineCount === 1 and the next getLineLength(line) call throws; for multi-line no-final-newline files it also moves Ctrl/Cmd+End to the penultimate line. Only subtract the extra line when the document actually has a trailing blank line, or clamp the result to the last valid line.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread packages/diffs/src/components/FileDiff.ts Outdated
@necolas

necolas commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The codex-flagged issues look real to me

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.

2 participants