Documentation
¶
Overview ¶
Package history provides undo/redo functionality via a change history stack.
Index ¶
- Constants
- type ActionType
- type Change
- type EditorInterface
- type Manager
- func (m *Manager) BeginTransaction()
- func (m *Manager) CanRedo() bool
- func (m *Manager) CanUndo() bool
- func (m *Manager) Clear()
- func (m *Manager) EndTransaction(cursorBefore types.Position)
- func (m *Manager) InTransaction() bool
- func (m *Manager) RecordChange(change Change)
- func (m *Manager) Redo() (bool, error)
- func (m *Manager) Undo() (bool, error)
Constants ¶
const DefaultMaxHistory = 100
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType int
ActionType indicates whether text was inserted or deleted, or a group transaction.
const ( InsertAction ActionType = iota DeleteAction // Text deleted from the buffer TransactionAction // A grouped transaction of multiple changes )
type Change ¶
type Change struct {
Type ActionType
Text []byte // Text inserted or text deleted (unused for TransactionAction)
StartPosition types.Position // Where the change began (unused for TransactionAction)
EndPosition types.Position // Position after inserted text, or end position of deleted text
CursorBefore types.Position // Cursor position *before* this change was applied
// For TransactionAction: the grouped sub-changes applied in order.
Children []Change
}
Change represents a single, reversible text operation, or a group transaction.
type EditorInterface ¶
type EditorInterface interface {
GetBuffer() buffer.Buffer
SetCursor(types.Position)
GetEventManager() *event.Manager
ScrollToCursor()
}
EditorInterface defines the methods the history manager needs from the editor/buffer.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the undo/redo stack.
func NewManager ¶
func NewManager(editor EditorInterface, maxHistory int) *Manager
NewManager creates a history manager.
func (*Manager) BeginTransaction ¶ added in v0.1.3
func (m *Manager) BeginTransaction()
BeginTransaction starts grouping subsequent RecordChange calls into a single atomic undo/redo step. Calls to BeginTransaction while a transaction is already open are ignored (no nested transactions).
func (*Manager) Clear ¶
func (m *Manager) Clear()
Clear resets the history stack. Call this on file load.
func (*Manager) EndTransaction ¶ added in v0.1.3
EndTransaction finalises the open transaction, recording all accumulated sub-changes as a single TransactionAction entry on the undo stack. If no changes were accumulated (empty transaction), nothing is recorded.
func (*Manager) InTransaction ¶ added in v0.1.3
InTransaction returns whether a transaction is currently open.
func (*Manager) RecordChange ¶
RecordChange adds a new change, clearing any redo history. When inside a transaction, the change is buffered instead of committed immediately.