Skip to content

enable undo cursor restoration for programmatic edits#1070

Open
Third-Thing wants to merge 1 commit intolapce:mainfrom
Third-Thing:b1222c25-no-tests
Open

enable undo cursor restoration for programmatic edits#1070
Third-Thing wants to merge 1 commit intolapce:mainfrom
Third-Thing:b1222c25-no-tests

Conversation

@Third-Thing
Copy link
Copy Markdown
Contributor

Refactor of #1062 to eliminate the compatibility problem.


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 #1058

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
@Third-Thing
Copy link
Copy Markdown
Contributor Author

Unrelated clippy complaints addressed in #1071

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant