Skip to content

refactor(editor): realtime update on diff editing#774

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

refactor(editor): realtime update on diff editing#774
ije wants to merge 31 commits into
beta-1.3from
editor/diff

Conversation

@ije
Copy link
Copy Markdown
Collaborator

@ije ije commented Jun 3, 2026

  • File: Update line-annotation DOM in place on move/delete (no full content rendering)
  • File: Skip full rerendering when edits only append lines at end of document
  • FileDiff: Force diff style to 'split'
  • FileDiff: Use incremental/partial diff&rendering

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

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

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

Request Review

@ije ije marked this pull request as ready for review June 5, 2026 16:57
Copilot AI review requested due to automatic review settings June 5, 2026 16:57
@ije ije changed the title refactor(editor): Improve re-rendering after typestroke refactor(editor): realtime update on diff editing Jun 5, 2026
Copy link
Copy Markdown

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

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: 97d4258c8c

ℹ️ 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 on lines +231 to +234
target.additionCount = parsed.additionCount;
target.deletionCount = parsed.deletionCount;
target.additionLines = parsed.additionLines;
target.deletionLines = parsed.deletionLines;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve hunk coordinates when applying reparsed slices

When a user edits a line in an existing hunk that includes surrounding context, reparseHunkRegion reparses the whole hunk slice with context: 0, so the returned hunk is usually relative to only the changed subrange. Copying parsed.additionCount/deletionCount into the original hunk without also translating parsed.additionStart/additionLineIndex shrinks the hunk while leaving its start at the old context line; subsequent render/count calculations then drop or misplace the hunk's context rows after ordinary in-place edits.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the diffs editor/rendering pipeline to reduce full rerenders after keystrokes by incrementally updating tokenization output, diff hunk metadata, and line-annotation DOM, while defaulting FileDiff rendering to split mode.

Changes:

  • Adds incremental diff-hunk recomputation (updateDiffHunks) and integrates it into DiffHunksRenderer for in-place updates during edits.
  • Refactors editor ↔ renderer integration (new syncToRenderedView, applyDocumentChange, updateRenderCache) and improves background tokenization scheduling (pause/resume, listener lifecycle).
  • Adds/updates annotation rendering utilities and forces default diffStyle: 'split' for FileDiff.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/diffs/test/updateDiffHunks.test.ts Adds targeted tests validating incremental hunk updates vs full recompute.
packages/diffs/test/editorTokenizer.test.ts Adds tests for message-listener lifecycle, pause/resume, and safe message handling.
packages/diffs/src/utils/updateDiffHunks.ts Implements incremental hunk reparsing + render-line-count recomputation helpers.
packages/diffs/src/types.ts Extends editor/component contracts (new methods/options like diffStyle, syncToRenderedView, cache dirty flag).
packages/diffs/src/renderers/FileRenderer.ts Renames/adjusts cache update + document-change hooks to align with new editor contract.
packages/diffs/src/renderers/DiffHunksRenderer.ts Adds render-cache mutation paths for incremental edits and document line-count changes.
packages/diffs/src/react/utils/useFileDiffInstance.ts Sets default FileDiff options to split diff style.
packages/diffs/src/editor/utils.ts Adds dataset parsing helper for line-number attributes.
packages/diffs/src/editor/tokenzier.ts Refactors background tokenization: listener lifecycle, pause/resume, safer message handling, state cache changes.
packages/diffs/src/editor/textDocument.ts Makes changedLineRanges required; updates getLineText signature.
packages/diffs/src/editor/sprite.ts Updates sprite attribute conventions and adds createSpriteElement helper.
packages/diffs/src/editor/selection.ts Minor logic reordering for editable-line detection.
packages/diffs/src/editor/pieceTable.ts Extends last-line cache to account for line-break inclusion option.
packages/diffs/src/editor/lineAnnotations.ts Adds DOM rendering/sync logic for diff line annotations and updates line-annotation shifting behavior.
packages/diffs/src/editor/editor.ts Major editor integration refactor: incremental DOM updates, renderer cache updates, fewer full rerenders, tokenization scheduling tweaks.
packages/diffs/src/editor/editor.css Adjusts selection/highlight background rules to better coexist with new DOM structure.
packages/diffs/src/components/VirtualizedFileDiff.ts Updates virtualized diff behavior when document line count changes (buffer/layout syncing).
packages/diffs/src/components/VirtualizedFile.ts Refactors layout-cache reset behavior on document line-count changes.
packages/diffs/src/components/FileDiff.ts Integrates incremental render-cache updates, split-style enforcement, and editor-driven rerender paths.
packages/diffs/src/components/File.ts Integrates new editor contract and postpones background tokenization during render.
apps/demo/src/main.ts Updates demo wiring to exercise the new editor/debug and selection normalization behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/diffs/src/utils/updateDiffHunks.ts
Comment thread packages/diffs/src/renderers/DiffHunksRenderer.ts
Comment thread packages/diffs/src/editor/lineAnnotations.ts
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