undo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 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) Checkpoint

func (l *Log) Checkpoint()

Checkpoint marks the current entry as a checkpoint.

func (*Log) HasUnsavedChanges

func (l *Log) HasUnsavedChanges() bool

HasUnsavedChanges returns whether the log has unsaved changes.

func (*Log) RedoToNextCheckpoint

func (l *Log) RedoToNextCheckpoint() []Op

RedoToNextCheckpoint returns operations to to transform the document to its state at the next checkpoint. It also moves the current position forward in the log.

func (*Log) TrackLoad

func (l *Log) TrackLoad()

TrackLoad removes all changes and resets the savepoint.

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

func (l *Log) UndoToLastCheckpoint() []Op

UndoToLastCheckpoint returns operations to transform the document back to its state at the previous checkpoint. It also moves the current position backwards in the 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