Documentation ¶
Index ¶
- type Action
- type ActionGroup
- type ActionType
- type Buffer
- func (b *Buffer) AddListener(c chan BufferEvent)
- func (b *Buffer) CleanupTrailingNewlines()
- func (b *Buffer) CleanupTrailingSpaces()
- func (b *Buffer) Delete(c Cursor, numBytes int)
- func (b *Buffer) DeleteLine(line *Line)
- func (b *Buffer) DeleteRange(from Cursor, to Cursor)
- func (b *Buffer) DeleteRune(c Cursor)
- func (b *Buffer) DeleteRuneBackward(c Cursor)
- func (b *Buffer) Emit(e BufferEvent)
- func (b *Buffer) EnsureTrailingEOL()
- func (b *Buffer) FinalizeActionGroup()
- func (b *Buffer) Insert(c Cursor, data []byte)
- func (b *Buffer) InsertLine(line *Line, prev *Line)
- func (b *Buffer) InsertRune(c Cursor, r rune)
- func (b *Buffer) Redo()
- func (b *Buffer) RemoveListener(c chan BufferEvent)
- func (b *Buffer) Save() error
- func (b *Buffer) SaveAs(filename string) error
- func (b *Buffer) SyncedWithDisk() bool
- func (b *Buffer) Undo()
- type BufferEvent
- type BufferEventType
- type BufferReader
- type Cursor
- func (c Cursor) Above(other Cursor) bool
- func (c Cursor) After(other Cursor) bool
- func (c *Cursor) BOF() bool
- func (c *Cursor) BOL() bool
- func (c Cursor) Before(other Cursor) bool
- func (c Cursor) Below(other Cursor) bool
- func (a Cursor) Distance(b Cursor) int
- func (c *Cursor) EOF() bool
- func (c *Cursor) EOL() bool
- func (c *Cursor) EndWord() bool
- func (c Cursor) Equals(other Cursor) bool
- func (c *Cursor) ExtractBytes(n int) []byte
- func (c *Cursor) FirstLine() bool
- func (c *Cursor) LastLine() bool
- func (c Cursor) LeftOf(other Cursor) bool
- func (c *Cursor) MoveBOL()
- func (c *Cursor) MoveEOL()
- func (c *Cursor) NextLine() bool
- func (c *Cursor) NextRune(wrap bool) bool
- func (c *Cursor) NextRuneFunc(f func(rune) bool) bool
- func (c *Cursor) NextWord() bool
- func (c *Cursor) OnDeleteAdjust(a *Action)
- func (c *Cursor) OnInsertAdjust(a *Action)
- func (c *Cursor) PrevLine() bool
- func (c *Cursor) PrevRune(wrap bool) bool
- func (c *Cursor) PrevRuneFunc(f func(rune) bool) bool
- func (c *Cursor) PrevWord() bool
- func (c Cursor) RightOf(other Cursor) bool
- func (c *Cursor) RuneAfter() (rune, int)
- func (c *Cursor) RuneBefore() (rune, int)
- func (c *Cursor) RuneUnder() (rune, int)
- func (c *Cursor) VoffsetCoffset() (vo, co int)
- func (c *Cursor) WordUnderCursor() []byte
- type Line
- type Range
- type RangeFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { What ActionType Data []byte Cursor Cursor Lines []*Line }
An action is a single entity of undo/redo history. All changes to contents of a buffer must be initiated by an action.
func NewDeleteAction ¶
NewDeleteAction creates a new action deleting numBytes bytes at c.
func NewInsertAction ¶
NewInsertAction creates a new action inserting data bytes at c.
func (*Action) DeletedLines ¶
returns the range of deleted lines, the first and the last one
type ActionGroup ¶
type ActionGroup struct { Actions []Action Next *ActionGroup Prev *ActionGroup }
func (*ActionGroup) Append ¶
func (ag *ActionGroup) Append(a *Action)
func (*ActionGroup) CursorAfter ¶
func (ag *ActionGroup) CursorAfter() Cursor
CursorBefore returns cursor position after actions in the group are applied.
func (*ActionGroup) CursorBefore ¶
func (ag *ActionGroup) CursorBefore() Cursor
CursorBefore returns cursor position before actions in the group are applied.
func (*ActionGroup) LastAction ¶
func (ag *ActionGroup) LastAction() *Action
Valid only as long as no new actions were added to the action group.
type ActionType ¶
type ActionType int
const ( ActionInsert ActionType = 1 ActionDelete ActionType = -1 )
type Buffer ¶
type Buffer struct { FirstLine *Line LastLine *Line NumLines int History *ActionGroup // absoulte path of the file, if it's empty string, then the file has no // on-disk representation Path string // buffer name (displayed in the status line), must be unique, // uniqueness is maintained by godit methods Name string // contains filtered or unexported fields }
func NewEmptyBuffer ¶
func NewEmptyBuffer() *Buffer
func (*Buffer) AddListener ¶
func (b *Buffer) AddListener(c chan BufferEvent)
func (*Buffer) CleanupTrailingNewlines ¶
func (b *Buffer) CleanupTrailingNewlines()
CleanupTrailingNewlines removes all but one trailing newlines.
func (*Buffer) CleanupTrailingSpaces ¶
func (b *Buffer) CleanupTrailingSpaces()
CleanupTrailingSpaces removes trailing whitespace characters from every line in the buffer.
func (*Buffer) DeleteLine ¶
func (*Buffer) DeleteRange ¶
func (*Buffer) DeleteRune ¶
If at the EOL, move contents of the next line to the end of the current line, erasing the next line after that. Otherwise, delete one character under the cursor.
func (*Buffer) DeleteRuneBackward ¶
If at the beginning of the line, move contents of the current line to the end of the previous line. Otherwise, erase one character backward.
func (*Buffer) Emit ¶
func (b *Buffer) Emit(e BufferEvent)
func (*Buffer) EnsureTrailingEOL ¶
func (b *Buffer) EnsureTrailingEOL()
EnsureTrailingEOL adds a newline at the end of the buffer, unless one exists already.
func (*Buffer) FinalizeActionGroup ¶
func (b *Buffer) FinalizeActionGroup()
func (*Buffer) InsertLine ¶
InsertLine inserts a line after prev in the buffer. If prev is nil then the line will be the new first line of the buffer.
func (*Buffer) InsertRune ¶
InsertRune inserts 'r' at the cursor position 'c'
func (*Buffer) RemoveListener ¶
func (b *Buffer) RemoveListener(c chan BufferEvent)
func (*Buffer) SyncedWithDisk ¶
type BufferEvent ¶
type BufferEvent struct { Type BufferEventType Action *Action }
type BufferEventType ¶
type BufferEventType int
const ( BufferEventInsert BufferEventType = iota BufferEventDelete BufferEventBOF BufferEventEOF BufferEventHistoryBack BufferEventHistoryStart BufferEventHistoryForward BufferEventHistoryEnd BufferEventSave )
type BufferReader ¶
type BufferReader struct { Line *Line // contains filtered or unexported fields }
type Cursor ¶
A Cursor represents a position within a buffer.
func SortCursors ¶
SortCursors orders a pair of cursors, from closest to furthest from the beginning of the buffer.
func (*Cursor) EndWord ¶
EndWord moves cursor to the end of current word or seeks to the beginning of next word, if character under cursor is a whitespace.
func (Cursor) Equals ¶
Equals reports whether the cursor position equals that of other. This function avoids a check for pointer equality of the Line pointer.
func (*Cursor) ExtractBytes ¶
ExtractBytes returns a slice of up to n bytes from the current cursor position.
func (*Cursor) MoveBOL ¶
func (c *Cursor) MoveBOL()
MoveBOL moves the cursor to the beginning of the current line.
func (*Cursor) MoveEOL ¶
func (c *Cursor) MoveEOL()
MoveEOL moves the cursor to the end of the current line.
func (*Cursor) NextLine ¶
NextLine moves the cursor to the next line. It reports whether the motion succeeded.
func (*Cursor) NextRune ¶
NextRune moves cursor to the next rune. If wrap is true, wraps the cursor to the beginning of next line once the end of the current one is reached. Returns true if motion succeeded, false otherwise.
func (*Cursor) NextRuneFunc ¶
Move cursor forward until current rune satisfies condition f. Returns true if the move was successful, false if EOF reached.
func (*Cursor) NextWord ¶
Move cursor forward to beginning of next word. Skips the rest of the current word, if any. Returns true if the move was successful, false if EOF reached.
func (*Cursor) OnDeleteAdjust ¶
func (*Cursor) OnInsertAdjust ¶
func (*Cursor) PrevLine ¶
PrevLine moves the cursor to the previous line. It reports whether the motion succeeded.
func (*Cursor) PrevRune ¶
PrevRune moves cursor to the previous rune. If wrap is true, wraps the cursor to the end of next line once the beginning of the current one is reached. Returns true if motion succeeded, false otherwise.
func (*Cursor) PrevRuneFunc ¶
Move cursor backward until current rune satisfies condition f. Returns true if the move was successful, false if EOF reached.
func (*Cursor) PrevWord ¶
Move cursor forward to beginning of the previous word. Skips the rest of the current word, if any, unless is located at its first character. Returns true if the move was successful, false if EOF reached.
func (Cursor) RightOf ¶
Right reports whether the cursor is to the right of other, regardless of line.
func (*Cursor) RuneAfter ¶
RuneAfter return the rune after the current cursor and its width in bytes.
func (*Cursor) RuneBefore ¶
RuneUnder returns the rune before the current cursor and its width in bytes.
func (*Cursor) RuneUnder ¶
RuneUnder returns the rune under the current cursor and its width in bytes.
func (*Cursor) VoffsetCoffset ¶
VoffsetCoffset returns a visual and a character offset for a given cursor.
func (*Cursor) WordUnderCursor ¶
type Line ¶
func (*Line) FindClosestOffsets ¶
Find a set of closest offsets for a given visual offset