View Source Yex.UndoManager (y_ex v0.7.2)
Represents a Y.UndoManager instance.
Summary
Functions
Clears all StackItems stored within current UndoManager, effectively resetting its state.
Excludes an origin from being tracked by the UndoManager.
Expands the scope of the UndoManager to include additional shared types. The scope can be a Text, Array, or Map type.
Includes an origin to be tracked by the UndoManager.
Creates a new UndoManager for the given document and scope with default options. The scope can be a Text, Array, Map, XmlText, XmlElement, or XmlFragment type.
Creates a new UndoManager with the given options.
Redoes the last undone change.
Stops capturing changes for the current stack item. This ensures that the next change will create a new stack item instead of being merged with the previous one, even if it occurs within the normal timeout window.
Undoes the last tracked change.
Types
Functions
Clears all StackItems stored within current UndoManager, effectively resetting its state.
Example:
text = Doc.get_text(doc, "text")
undo_manager = UndoManager.new(doc, text)
Text.insert(text, 0, "Hello")
Text.insert(text, 5, " World")
UndoManager.clear(undo_manager)
# All undo/redo history is now cleared
Excludes an origin from being tracked by the UndoManager.
Expands the scope of the UndoManager to include additional shared types. The scope can be a Text, Array, or Map type.
Includes an origin to be tracked by the UndoManager.
Creates a new UndoManager for the given document and scope with default options. The scope can be a Text, Array, Map, XmlText, XmlElement, or XmlFragment type.
Errors
- Returns
{:error, "Invalid scope: expected a struct"}
if scope is not a struct - Returns
{:error, "Failed to get branch reference"}
if there's an error accessing the scope
@spec new_with_options(Yex.Doc.t(), struct(), Yex.UndoManager.Options.t()) :: {:ok, t()} | {:error, term()}
Creates a new UndoManager with the given options.
Options
See Yex.UndoManager.Options
for available options.
Errors
- Returns
{:error, "NIF error: <message>"}
if underlying NIF returns an error
Redoes the last undone change.
Stops capturing changes for the current stack item. This ensures that the next change will create a new stack item instead of being merged with the previous one, even if it occurs within the normal timeout window.
Example:
text = Doc.get_text(doc, "text")
undo_manager = UndoManager.new(doc, text)
Text.insert(text, 0, "a")
UndoManager.stop_capturing(undo_manager)
Text.insert(text, 1, "b")
UndoManager.undo(undo_manager)
# Text.to_string(text) will be "a" (only "b" was removed)
Undoes the last tracked change.