struct UndoStack
Swift
struct UndoStack
Undo/redo history for a single buffer.
Coalescing is deliberately time-free. A timer makes the split points depend on how fast someone types, which is both untestable and surprising ("why did that undo only half a word?"). Instead a run breaks on a word boundary, a direction change, or anything that is not a simple continuation — deterministic, and it matches where a user thinks a word ended.
Sources/LavaText/TextEdit.swift:68
Constructors
init()
Creates an empty history.
Sources/LavaText/TextEdit.swift:73
Properties
var canRedo: Bool { get }
Whether there is an undone edit to redo.
Sources/LavaText/TextEdit.swift:78
var canUndo: Bool { get }
Whether there is an edit to undo.
Sources/LavaText/TextEdit.swift:76
Methods
mutating func clear()
Forgets all history.
Sources/LavaText/TextEdit.swift:111
mutating func popRedo() -> TextEdit?
Takes the most recently undone edit and moves it back to undo. Returns it to be applied again.
Sources/LavaText/TextEdit.swift:104
mutating func popUndo() -> TextEdit?
Takes the most recent edit off the undo history and moves it to redo.
Returns it, still in its forward form: apply its inverted to undo it.
Sources/LavaText/TextEdit.swift:96
mutating func record(_ edit: TextEdit)
Records a new edit, merging it into the previous one when the two read as one action (typing on through a word, say). Clears the redo history.
Sources/LavaText/TextEdit.swift:82