Make standalone rich spans (highlight/link/HR) undoable#26
Merged
Conversation
addRichSpan/removeRichSpan mutated RichSpanManager directly and never called editManager.recordEdit, so applying or removing a list/format span was invisible to undo/redo and Ctrl+Z/Ctrl+Y operated on the previous text edit instead. Add a TextEditOperation.RichSpan variant mirroring StyleSpan, route the addRichSpan/removeRichSpan overloads through editManager, and reverse it as a self-inverse op. Document-loading and paragraph-indent block paths keep the direct manager path so they don't pollute or half-apply through history. Fixes #20 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merge origin/main and fix non-exhaustive 'when' over TextEditOperation in SpellCheckState.invalidateSpellCheckSpans for the new RichSpan variant. Co-Authored-By: Claude Opus 4.8 <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.
Summary
Adds undo/redo support for standalone rich-span operations (highlight, link, horizontal-rule insertion) by routing
addRichSpan/removeRichSpanthrough the edit history.What changed
TextEditOperation.RichSpan(range, style, isAdd, cursorBefore, cursorAfter)mirroringStyleSpan; undo is a self-inverse op flippingisAdd, redo replays.addRichSpan/removeRichSpanoverloads onTextEditorStatenow record history viaeditManager.restorePreservedRichSpansand document-load (importMarkdownHR/image) + paragraph-indent block paths use the direct manager path so undo/redo internals don't double-record and document loading doesn't pollute history.RichSpanUndoTests/RichSpanRedoTests.Scope note
This does not make line-block toggles (numbered/bulleted lists, blockquote, code fence) undoable. Those route through
applyLineBlock/demoteLineBlock, which change paragraph indent viaupdateLine(not history-tracked) in addition to adding a span — recording only the span would leave a half-applied block. Making them atomically undoable needs a compound history entry capturing both halves; tracked in #20.Related: #20