undo

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log tracks changes to a document and generates undo/redo operations.

func NewLog

func NewLog() *Log

NewLog constructs a new, empty undo log.

func (*Log) BeginEntry added in v1.0.0

func (l *Log) BeginEntry(cursorPos uint64)

BeginEntry starts a new undo entry. This should be called before tracking any operations.

func (*Log) CommitEntry added in v1.0.0

func (l *Log) CommitEntry(cursorPos uint64)

CommitEntry completes an undo entry. This should be called after BeginEntry. If no operations were tracked, this does nothing.

func (*Log) HasUnsavedChanges

func (l *Log) HasUnsavedChanges() bool

HasUnsavedChanges returns whether the log has unsaved changes.

func (*Log) RedoToNextCommitted added in v1.0.0

func (l *Log) RedoToNextCommitted() (hasEntry bool, ops []Op, cursor uint64)

RedoToNextCommitted returns operations to to transform the document to its state after the next entry. It also moves the current position forward in the log.

func (*Log) TrackOp

func (l *Log) TrackOp(op Op)

TrackOp tracks a change to the document. This appends a new, uncommitted change and invalidates any future changes.

func (*Log) TrackSave

func (l *Log) TrackSave()

TrackSave moves the savepoint to the current entry.

func (*Log) UndoToLastCommitted added in v1.0.0

func (l *Log) UndoToLastCommitted() (hasEntry bool, ops []Op, cursor uint64)

UndoToLastCommitted returns operations to transform the document back to its state before the last entry. It also moves the current position backwards in the log.

type LogEntry added in v1.0.0

type LogEntry struct {
	Ops         []Op
	CursorBegin uint64
	CursorEnd   uint64
}

LogEntry represents an entry in the undo log.

type Op

type Op struct {
	// contains filtered or unexported fields
}

Op represents an insert or delete operation on a document.

func DeleteOp

func DeleteOp(pos uint64, text string) Op

DeleteOp constructs a new operation to delete text at a position.

func InsertOp

func InsertOp(pos uint64, text string) Op

InsertOp constructs a new operation to insert text at a position.

func (Op) Inverse

func (op Op) Inverse() Op

Inverse returns an op that reverses the effect of the op.

func (Op) NumRunesToDelete

func (op Op) NumRunesToDelete() int

NumRunesToDelete returns the number of runes deleted at the position. This will be zero if TextToInsert is a non-empty string.

func (Op) Position

func (op Op) Position() uint64

Position returns the position at which the operation occurred.

func (Op) TextToInsert

func (op Op) TextToInsert() string

TextToInsert returns the text inserted by the op. This will be an empty string if NumRunesToDelete is greater than zero.

Jump to

Keyboard shortcuts

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