Skip to content

Make standalone rich spans (highlight/link/HR) undoable#26

Merged
Wavesonics merged 3 commits into
mainfrom
fix/issue-20-list-undo-redo
Jun 12, 2026
Merged

Make standalone rich spans (highlight/link/HR) undoable#26
Wavesonics merged 3 commits into
mainfrom
fix/issue-20-list-undo-redo

Conversation

@Wavesonics

@Wavesonics Wavesonics commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Adds undo/redo support for standalone rich-span operations (highlight, link, horizontal-rule insertion) by routing addRichSpan/removeRichSpan through the edit history.

What changed

  • New TextEditOperation.RichSpan(range, style, isAdd, cursorBefore, cursorAfter) mirroring StyleSpan; undo is a self-inverse op flipping isAdd, redo replays.
  • addRichSpan/removeRichSpan overloads on TextEditorState now record history via editManager.
  • restorePreservedRichSpans and document-load (importMarkdown HR/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.
  • New 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 via updateLine (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

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>
@Wavesonics Wavesonics changed the title Record rich-span (list/format) operations in undo history (#20) Make standalone rich spans (highlight/link/HR) undoable Jun 12, 2026
@Wavesonics Wavesonics marked this pull request as ready for review June 12, 2026 06:07
Wavesonics and others added 2 commits June 11, 2026 23:51
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>
@Wavesonics Wavesonics merged commit 9ef1e31 into main Jun 12, 2026
1 check passed
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