Repository navigation
feat(editor): apply the app's text outside the undo history - #2518
Open
im-apratap wants to merge 1 commit into
Open
im-apratap wants to merge 1 commit into
im-apratap wants to merge 1 commit into
Conversation
An editor fed through Value recorded the app's text as an undo step, so a merge from a sync server became a step the user's Ctrl+Z took back, and there was no other call that applied text without recording one. replaceText now records only when asked: without it the buffer rebases the undo and redo steps, and the selections they restore, through the change, so undo still takes back the user's own edits around the merge. Ref.SetValueOutsideHistory applies text that way, and the editor's Value does the same. Part of nsgo-dev#2409. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This branch has not been deployed
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.
Item 5 of #2409: "Apply an edit that the undo history does not record, and map the history and the selections through it." Items 1–3 (hidden and replaced ranges, widgets in and between lines) and 4 (per-line height) are untouched.
The problem
Editor.Valueis the app's text, andfollowapplied a changed value throughstate.replaceText, which always calledbuf.record. A merge from a sync server, or another app's write to the file, therefore became a step the user's Ctrl+Z took back.Refhad no call that applied text without adding a step, and no way to keep the history coherent across such a change.What changes
state.replaceText(text, recorded)records a step only when asked. Without it,buffer.rebase(changes)carries every undo and redo step through the change — itsfrom,oldEndandnewEnd, and the selectionsbeforeandafterrestore — so the history still applies to the text as the merge left it, and undo takes back the user's own edits around it.Ref.SetValueOutsideHistory(text)is the public call: it replaces the text asSetValuedoes, reports it throughOnChange, but adds no undo step.Editor.Valueuses the same path, so an app that feeds a store intoValueno longer puts its own writes in the undo history.A change that overlaps a step leaves that step's range at the change's edge, the same collapse
mapThroughgives every edit that overlaps another.Verification
go tool nsgo check -target linux— vetted forlinux_arm64andlinux_x64.go tool nsgo test ./base/editor— 25 passed, including the newTestSetValueOutsideHistory: the user types, the app merges a line in, undo removes the typed text and keeps the merge, redo puts it back.go tool nsgo test -run 'Editor|Code' ./examples/gallery— 6 passed.go run ./tools/changelog check— valid.🤖 Generated with Codebuff