enable undo cursor restoration for programmatic edits#1070
Open
Third-Thing wants to merge 1 commit intolapce:mainfrom
Open
enable undo cursor restoration for programmatic edits#1070Third-Thing wants to merge 1 commit intolapce:mainfrom
Third-Thing wants to merge 1 commit intolapce:mainfrom
Conversation
Problem: Programmatic document edits currently bypass the editor context that undo cursor restoration depends on. `Document::edit` and `edit_single` mutate the buffer and emit deltas, but they do not record `cursor_before` / `cursor_after`, so undo lacks the initiating editor state needed to restore the cursor correctly. That left floem’s examples using raw document edits from button callbacks and compensating with workarounds like disabling undo in one shared editor. Solution: Add additive editor-aware document edit APIs: `edit_from` and `edit_single_from`. `TextDocument` uses the initiating editor to capture cursor-before state, apply the edit, remap that editor’s cursor through the produced deltas, and record cursor-after state on the revision. Raw `edit` / `edit_single` remain unchanged as low-level document mutation APIs, while UI-driven edits can now preserve expected cursor and undo behavior without changing the broader document-centered reactive model. Reasoning: This keeps the architecture aligned with floem’s existing update flow. Live cursor consistency across editors still comes from document deltas and update listeners; the new APIs only add what undo needs. The examples are moved to the editor-aware path, which removes the need to suppress undo in the secondary editor and makes the intended API split explicit. Associated with issue lapce#1058
Contributor
Author
|
Unrelated clippy complaints addressed in #1071 |
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.
Refactor of #1062 to eliminate the compatibility problem.
Problem: Programmatic document edits currently bypass the editor context that undo cursor restoration depends on.
Document::editandedit_singlemutate the buffer and emit deltas, but they do not recordcursor_before/cursor_after, so undo lacks the initiating editor state needed to restore the cursor correctly. That left floem’s examples using raw document edits from button callbacks and compensating with workarounds like disabling undo in one shared editor.Solution: Add additive editor-aware document edit APIs:
edit_fromandedit_single_from.TextDocumentuses the initiating editor to capture cursor-before state, apply the edit, remap that editor’s cursor through the produced deltas, and record cursor-after state on the revision. Rawedit/edit_singleremain unchanged as low-level document mutation APIs, while UI-driven edits can now preserve expected cursor and undo behavior without changing the broader document-centered reactive model.Reasoning: This keeps the architecture aligned with floem’s existing update flow. Live cursor consistency across editors still comes from document deltas and update listeners; the new APIs only add what undo needs. The examples are moved to the editor-aware path, which removes the need to suppress undo in the secondary editor and makes the intended API split explicit.
Associated with issue #1058