Skip to content

Undo/redo does not track list operations and undoes the wrong action #20

@Wavesonics

Description

@Wavesonics

Description

Undo/redo is broken when the most recent action is a list (rich-span) operation.

Example: type a character, then select some lines and turn them into a numbered list.

  • Ctrl+Z removes the numbered list and also reverts the character you typed before it.
  • Ctrl+Y does not bring the list back — it re-applies the character instead.

So the list toggle is effectively invisible to the history stack, and undo/redo operate on the previous edit.

Expected

Toggling a list should be a single, independently undoable/redoable step.

Root cause

addRichSpan(...) / removeRichSpan(...) mutate richSpanManager directly and never call editManager.recordEdit(...) — see src/commonMain/kotlin/com/darkrockstudios/texteditor/state/TextEditorState.kt:787-810. Because the list toggle isn't pushed onto the undo queue (TextEditHistory, src/commonMain/kotlin/com/darkrockstudios/texteditor/state/TextEditHistory.kt), undo()/redo() pop the prior text edit instead.

Fix likely means recording rich-span add/remove as history entries (a new TextEditOperation variant or metadata) so they round-trip through undo/redo.


Reported by a user of the Hammer editor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions