history

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package history provides undo/redo functionality via a change history stack.

Index

Constants

View Source
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.

const (
	InsertAction ActionType = iota
	DeleteAction
)

type Change

type Change struct {
	Type          ActionType
	Text          []byte         // Text inserted or text deleted
	StartPosition types.Position // Where the change began
	EndPosition   types.Position // Position after inserted text, or end position of deleted text
	CursorBefore  types.Position // Cursor position *before* this change was applied
}

Change represents a single, reversible text operation.

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) CanRedo

func (m *Manager) CanRedo() bool

CanRedo returns true if there are changes that can be redone.

func (*Manager) CanUndo

func (m *Manager) CanUndo() bool

CanUndo returns true if there are changes that can be undone.

func (*Manager) Clear

func (m *Manager) Clear()

Clear resets the history stack. Call this on file load.

func (*Manager) RecordChange

func (m *Manager) RecordChange(change Change)

RecordChange adds a new change, clearing any redo history.

func (*Manager) Redo

func (m *Manager) Redo() (bool, error)

Redo reapplies the last undone change.

func (*Manager) Undo

func (m *Manager) Undo() (bool, error)

Undo reverts the last recorded change.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL