Yex.UndoManager (y_ex v0.7.3)

View Source

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

t()

@type t() :: %Yex.UndoManager{doc: Yex.Doc.t(), reference: reference()}

Functions

clear(undo_manager)

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

exclude_origin(undo_manager, origin)

Excludes an origin from being tracked by the UndoManager.

expand_scope(undo_manager, scope)

Expands the scope of the UndoManager to include additional shared types. The scope can be a Text, Array, or Map type.

include_origin(undo_manager, origin)

Includes an origin to be tracked by the UndoManager.

is_valid_scope(scope)

(macro)

new(doc, scope)

@spec new(
  Yex.Doc.t(),
  struct()
) :: {:ok, t()} | {:error, term()}

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

new_with_options(doc, scope, options)

@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

redo(undo_manager)

Redoes the last undone change.

stop_capturing(undo_manager)

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)

undo(undo_manager)

Undoes the last tracked change.