gapbuffer

package
v0.0.0-...-99b4a15 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: Apache-2.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 GapBuffer

type GapBuffer[T ~int | ~rune] struct {
	Buffer   []T // NOTE: In the future I might want this to be a pointer. I avoided this for now as it looked ugly
	GapStart int // Index of the first character *in* the gap
	GapEnd   int // Index of the first character *after* the gap
}

Gap Buffer implementation. See: https://routley.io/posts/gap-buffer

func NewGapBuffer

func NewGapBuffer[T ~int | ~rune](content []T) GapBuffer[T]

NewGapBuffer creates a new gapbuffer and populates it with content

func (*GapBuffer[T]) Backspace

func (b *GapBuffer[T]) Backspace()

Backspace deletes the character before the current position

func (*GapBuffer[T]) Collect

func (b *GapBuffer[T]) Collect() []T

Collect returns a slice of the content of the gap buffer, without gap

func (*GapBuffer[T]) Count

func (b *GapBuffer[T]) Count() int

Count returns the size of the raw text, excliding the gap

func (*GapBuffer[T]) CursorGoto

func (b *GapBuffer[T]) CursorGoto(pos int)

CursorGoto moves the cursor to the given position

func (*GapBuffer[T]) CursorLeft

func (b *GapBuffer[T]) CursorLeft()

CursorRight moves the cursor left one character.

func (*GapBuffer[T]) CursorRight

func (b *GapBuffer[T]) CursorRight()

CursorRight moves the cursor right one character.

func (*GapBuffer[T]) Delete

func (b *GapBuffer[T]) Delete()

Delete deletes the character at the current cursor position.

func (*GapBuffer[T]) FindAll

func (b *GapBuffer[T]) FindAll(val T) []int

FindAll returns a slice with the indices of all found items inside the gap buffer

func (*GapBuffer[T]) Get

func (b *GapBuffer[T]) Get(pos int) T

Get returns the element at the given position.

func (*GapBuffer[T]) Insert

func (b *GapBuffer[T]) Insert(el T)

Insert inserts a single element at the current cursor position.

func (*GapBuffer[T]) InsertElements

func (b *GapBuffer[T]) InsertElements(elements []T)

InsertElements inserts a slice of T at the current cursor position.

func (*GapBuffer[T]) Iter

func (b *GapBuffer[T]) Iter() GapBufferIterator[T]

func (*GapBuffer[T]) Len

func (b *GapBuffer[T]) Len() int

Len returns the total length of the gap buffer, including gap

func (*GapBuffer[T]) TotalLen

func (b *GapBuffer[T]) TotalLen() int

TotalLen returns the total length of the gap buffer (including gaps)

type GapBufferIterator

type GapBufferIterator[T ~int | ~rune] struct {
	// contains filtered or unexported fields
}

func (*GapBufferIterator[T]) HasNext

func (gi *GapBufferIterator[T]) HasNext() bool

func (*GapBufferIterator[T]) Next

func (gi *GapBufferIterator[T]) Next() (int, T)

Jump to

Keyboard shortcuts

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