Repository navigation
Reload from disk as one undoable edit, keeping the caret (#1279) - #1286
Merged
Merged
Conversation
EditableContent.reload() reads the file again (the stable read of #1276; large files decoded while read) and replaces only the lines between the common first and last lines (reloadReplacement) as one undoable edit with the new action EditAction.Reload. The undo history stays: undo restores the text from before the reload, then earlier edits. The content is then saved, with the new fileState, format and invalid characters, already when listeners get the reload edit (no modified flicker); undoing it makes the content modified. Read-only content reloads too. Typing is never merged into a reload step. Editors handle Reload (also its undo and redo) by clearing the selection and keeping the caret, clamped to the new text; the scroll position stays, no smart indent. LineIcons.updateLinePositions() handles whole-line edits (all positions at column 0): the line a range ends at moves with the following lines instead of losing its icon, icons on removed lines are removed, inserted lines push the icons down. This also fixes deleting or pasting whole lines in normal editing. load(InputStream) and reload share decodeText(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1279 (part of #1274, phase 2 of #783)
Reloading after an external change used to mean
load(): the undo history was cleared and the caret jumped to the start. As decided by the owner, a reload is now one undo step: the history stays valid, the selection is cleared, and the caret is kept, clamped to the new text.EditableContent.reload(source)maxInMemoryLoadSizeare decoded while read).reloadReplacement()), so bookmarks and breakpoints on unchanged lines stay with their lines.EditAction.Reload:fileState, format and invalid-character data. Listeners see all of this already in the reload notification, so there's no modified/unmodified flicker. Undoing the reload makes the content modified.Editors
For
Reload, and for its undo and redo, from any source:Line icons on whole-line edits (also normal editing)
LineIcons.updateLinePositions()treated the line a range ends at (column 0) as removed. Selecting lines 2–3 up to the start of line 4 and deleting them dropped line 4's bookmark or breakpoint, while line 2's stayed and ended up on the old line 4. Pasting whole lines at a line start left that line's icon on the first inserted line.For edits whose positions are all at column 0:
Other edits behave as before.
Also
load(InputStream)andreload()sharedecodeText().performOperation()'s replace is factored intoapplyReplace().Tests
reloadReplacement(), 12 cases (middle, either end, empty before or after, repeated lines). Each is applied, undone and redone with a bookmark on every old line: the unchanged first and last lines keep theirs at their new positions, and no line gets two. Fails with the oldupdateLinePositions().reload():Checked
dub testwith LDC 1.36 (37 modules), DMD 2.107 (37), the-preview=dip1000build (37),-c console(34), and on Windows (38). D-Scanner clean.EditBoxwith the caret at 30:20 and a selection 28:5–30:20; the file is shortened to 35 short lines and reloaded:modifiedStateChangefired only for the undo and the redo. The screenshots match, and there were no leak lines at exit.🤖 Generated with Claude Code