Skip to content

package memento

import "kaiju/editor/memento"

Types

History

struct

type History struct {
    // Has unexported fields.
}

History.Add

func (h *History) Add(m Memento)

Add inserts a new memento into the history. If a transaction is active, the memento is queued instead of being added immediately.

History.AddOrReplaceLast

func (h *History) AddOrReplaceLast(m Memento)

AddOrReplaceLast inserts a new memento into the history. If the most recent memento (the one at h.position‑1) has the same concrete type as the supplied memento, it is replaced instead of creating a new entry. This is useful for collapsing consecutive operations of the same kind (e.g. repeated brush strokes) into a single undo step.

History.BeginTransaction

func (h *History) BeginTransaction()

BeginTransaction starts a new transaction. Subsequent Add calls will be queued in the transaction until it is committed or cancelled. If committed all of the undos will be joined together into a single undo/redo operation. You should start a transaction when calling common methods that would create their own internal history.

For example, when you delete selected entities, the clear function is called on the selection (to update UI, visuals, and other things). This clear call will generate history, thus creating 2 history entries (clear and delete). By starting a transaction, both of those will be within the same undo/redo call.

History.CancelTransaction

func (h *History) CancelTransaction()

CancelTransaction aborts the current transaction, discarding any queued mementos.

History.Clear

func (h *History) Clear()

Clear removes all mementos from the history and resets the position.

History.CommitTransaction

func (h *History) CommitTransaction()

CommitTransaction finalizes the current transaction, adding all queued mementos to the history as a single atomic operation.

History.HasPendingChanges

func (h *History) HasPendingChanges() bool

HasPendingChanges reports whether the history has changes since the last saved position.

History.Initialize

func (h *History) Initialize(limit int)

Initialize sets the max number of undo entries that the history will retain.

History.IsInTransaction

func (h *History) IsInTransaction() bool

IsInTransaction reports whether a history transaction is currently active.

History.Last

func (h *History) Last() (Memento, bool)

History.LockAdditions

func (h *History) LockAdditions()

LockAdditions prevents new mementos from being added to the history.

History.Redo

func (h *History) Redo()

Redo reapplies the next memento in the stack, moving the position forward.

History.SetSavePosition

func (h *History) SetSavePosition()

SetSavePosition records the current position as the saved state.

History.Undo

func (h *History) Undo()

Undo reverts the most recent memento, moving the current position back.

History.UnlockAdditions

func (h *History) UnlockAdditions()

UnlockAdditions re-enables adding new mementos after a lock.

HistoryTransaction

struct

type HistoryTransaction struct {
    // Has unexported fields.
}

HistoryTransaction.Delete

func (h *HistoryTransaction) Delete()

HistoryTransaction.Exit

func (h *HistoryTransaction) Exit()

HistoryTransaction.Redo

func (h *HistoryTransaction) Redo()

HistoryTransaction.Undo

func (h *HistoryTransaction) Undo()

Memento

interface

type Memento interface {
    Redo()   // Called to redo the action
    Undo()   // Called to undo the action
    Delete() // Called when the undo state is overridden by new undo data
    Exit()   // Called when the undo state falls off the history list
}