refactor(editor): realtime update on diff editing#774
Conversation
…d for the `DiffsEditor`
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 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".
| target.additionCount = parsed.additionCount; | ||
| target.deletionCount = parsed.deletionCount; | ||
| target.additionLines = parsed.additionLines; | ||
| target.deletionLines = parsed.deletionLines; |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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 intoDiffHunksRendererfor 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.
Uh oh!
There was an error while loading. Please reload this page.