Skip to content

feat(editor): apply the app's text outside the undo history - #2518

Open
im-apratap wants to merge 1 commit into
nsgo-dev:mainfrom
im-apratap:feat/editor-unrecorded
Open

im-apratap wants to merge 1 commit into
nsgo-dev:mainfrom
im-apratap:feat/editor-unrecorded

Conversation

@im-apratap

Copy link
Copy Markdown

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.Value is the app's text, and follow applied a changed value through state.replaceText, which always called buf.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.
  • Ref had 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 — its from, oldEnd and newEnd, and the selections before and after restore — 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 as SetValue does, reports it through OnChange, but adds no undo step.
  • Editor.Value uses the same path, so an app that feeds a store into Value no 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 mapThrough gives every edit that overlaps another.

Verification

  • go tool nsgo check -target linux — vetted for linux_arm64 and linux_x64.
  • go tool nsgo test ./base/editor — 25 passed, including the new TestSetValueOutsideHistory: 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

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>
@github-actions github-actions Bot added size/M documentation Improvements or additions to documentation base enhancement New feature or request labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

base documentation Improvements or additions to documentation enhancement New feature or request size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant