edit

package module
v0.0.0-...-805ca86 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Unlicense Imports: 4 Imported by: 1

README

edit

A text editor utility library for Go (golang).

Installation

go get -u github.com/jangler/edit

Documentation

Projects

Documentation

Overview

Package edit implements a thread-safe text-editing buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer is a thread-safe text-editing buffer.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer initializes and returns a new empty Buffer.

func (*Buffer) CoordsFromIndex

func (b *Buffer) CoordsFromIndex(index Index) (col, row int)

CoordsFromIndex returns the display coordinates of index. Coordinates may be out of bounds of the buffer's current display.

func (*Buffer) Delete

func (b *Buffer) Delete(begin, end Index)

Delete removes the text in the buffer between begin and end.

func (*Buffer) DisplayLines

func (b *Buffer) DisplayLines() []*list.List

DisplayLines returns a slice of Lists of Fragments, one list for each line on the buffer's current display.

func (*Buffer) End

func (b *Buffer) End() Index

End returns an Index after the last character in the Buffer.

func (*Buffer) Get

func (b *Buffer) Get(begin, end Index) string

Get returns the text in the Buffer between begin and end.

func (*Buffer) IndexFromCoords

func (b *Buffer) IndexFromCoords(col, row int) Index

IndexFromCoords returns the closest index to the given display coordinates.

func (*Buffer) IndexFromMark

func (b *Buffer) IndexFromMark(id int) Index

IndexFromMark returns the current index of the mark with ID id, or a zero-value index if no mark with ID id is set.

func (*Buffer) Insert

func (b *Buffer) Insert(index Index, text string)

Insert inserts text into the buffer at index.

func (*Buffer) Mark

func (b *Buffer) Mark(index Index, id ...int)

Mark sets a mark with ID id at index. The mark's position is automatically updated when the buffer contents are modified. If a mark with ID id already exists, its position is updated. Multiple IDs can be specified to set multiple marks at the same time.

func (*Buffer) Modified

func (b *Buffer) Modified() bool

Modified returns true if and only if the buffer's contents differ from the contents at the last time ResetModified was called. This operation is expsensive, since it must hash the entire buffer contents.

func (*Buffer) Redo

func (b *Buffer) Redo(mark ...int) bool

Redo redoes the last undone sequence of insertions and deletions and returns true, or returns false if the redo stack is empty. The given marks are positioned at the index of the redone operation.

func (*Buffer) ResetModified

func (b *Buffer) ResetModified()

ResetModified sets the comparison point for future calls to Modified to the current contents of the buffer. This operation is expensive, since it must hash the entire buffer contents.

func (*Buffer) ResetUndo

func (b *Buffer) ResetUndo()

ResetUndo clears the buffer's undo and redo stacks.

func (*Buffer) Scroll

func (b *Buffer) Scroll(delta int)

Scroll scrolls the buffer's display down by delta lines.

func (*Buffer) ScrollFraction

func (b *Buffer) ScrollFraction() float64

ScrollFraction returns a number in the range [0, 1] describing the vertical scroll fraction of the buffer display. If the entire content is visible, -1 is returned instead.

func (*Buffer) Separate

func (b *Buffer) Separate()

Separate inserts a separator onto the undo stack in order to delimit sequences of insertions and deletions.

func (*Buffer) SetSize

func (b *Buffer) SetSize(cols, rows int)

SetSize sets the display size of the buffer.

func (*Buffer) SetSyntax

func (b *Buffer) SetSyntax(rules []Rule)

SetSyntax sets the syntax highlighting rules for the buffer to rules.

func (*Buffer) SetTabWidth

func (b *Buffer) SetTabWidth(cols int)

SetTabWidth sets the tab width of the buffer to cols.

func (*Buffer) ShiftIndex

func (b *Buffer) ShiftIndex(index Index, chars int) Index

ShiftIndex returns index shifted right by chars. If chars is negative, index is shifted left.

func (*Buffer) Undo

func (b *Buffer) Undo(mark ...int) bool

Undo undoes the last sequence of insertions and deletions and returns true, or returns false if the redo stack is empty. The given marks are positioned at the index of the undone operation.

type Fragment

type Fragment struct {
	Text string
	Tag  int
}

Fragment is a string annotated with a tag.

type Index

type Index struct {
	Line, Char int
}

Index denotes a position in a Buffer.

func (*Index) Less

func (i *Index) Less(other Index) bool

Less returns true if the index is less than other.

type Rule

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

Rule is a rule for matching syntax and applying a tag to it.

func NewRule

func NewRule(pattern string, tag int) (Rule, error)

NewRule returns an initialized Rule by compiling pattern into a regular expression, or returns an error if pattern fails to compile.

Jump to

Keyboard shortcuts

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