[diffs/editor] Fix diff rerener in edit mode#878
Conversation
|
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: 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".
| const line = atEnd | ||
| ? textDocument.lineCount - (endNewLineTrimmed === true ? 2 : 1) | ||
| : 0; | ||
| const character = atEnd ? textDocument.getLineLength(line) : 0; |
There was a problem hiding this comment.
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 👍 / 👎.
|
The codex-flagged issues look real to me |
94717e0 to
da2129f
Compare
…lank lines and add corresponding unit tests
…sureGrammar method and add unit test for dynamic grammar loading
On the /edit demo, toggle Edit mode off and back on, or switch the surface between File and Diff, then type: the caret appears but the typed characters never show up, even though the document records them. Detaching the editor (cleanUp) tears down the tokenizer but left the parsed document and its file identity in place. On re-attach, __syncRenderView saw the same file name, lang, and cacheKey, treated the file as unchanged, and skipped the rebuild that recreates the tokenizer; with none, #rerender bailed before painting. Release the document and file info in cleanUp so the next edit() rebuilds both from the host's current contents. Also drop a stale LiveEditing comment about recreating the editor per control change, which the dependency array no longer does.
- alway ensure change even no editor attended - remove `applyContentEdit` and `recomputeContentHunks`
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
refreshUnifiedDiffView/refreshSplitDiffView) and debounce both at 150ms after edits.applyDocumentChangeupdates diff metadata in place instead of forcing a full re-render on every keystroke.Editor state & cache
rerenderFromDocument/ DOM-divergence path. The editor now defaultscacheKeyto the file name (orprevName->namefor renames) so editing state survives scroll-driven partial re-renders without walking the DOM. @necolasisLineVisiblechecks for a rendered line element instead of relying onrenderRange, which broke caret/selection overlays in virtualized diffs.scrollIntoViewto the next animation frame to reduce scroll jitter when adding/removing lines.moveCursorToDocEnd/getDocumentBoundarySelectionfor diff documents with trailing blank lines, no final newline, or a single-line buffer.Virtualization & hunk recompute
getLayoutLineCountso render-range clamping uses the live diff size even when layout checkpoints are stale after edits.renderRangeacross in-edit layout resets; recompute buffer spacers when the document grows below the rendered window.recomputeDiffHunksForEditwith 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.