textbuffer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package textbuffer provides a multi-line text editor with cursor movement, history navigation, and auto-completion support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType int

ActionType is the type of edit action.

const (
	ActionInsert ActionType = iota
	ActionDelete
	ActionReplace
)

type Buffer

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

Buffer represents a text buffer for multi-line editing.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new text buffer.

func (*Buffer) AddToHistory

func (b *Buffer) AddToHistory()

AddToHistory adds the current text to history.

func (*Buffer) Clear

func (b *Buffer) Clear()

Clear clears the entire buffer.

func (*Buffer) Cursor

func (b *Buffer) Cursor() (int, int)

Cursor returns the current cursor position (row, col).

func (*Buffer) CursorOffset

func (b *Buffer) CursorOffset() int

CursorOffset returns the cursor offset from the start of the text.

func (*Buffer) DeleteChar

func (b *Buffer) DeleteChar()

DeleteChar deletes the character before the cursor (backspace).

func (*Buffer) DeleteCharForward

func (b *Buffer) DeleteCharForward()

DeleteCharForward deletes the character at the cursor position.

func (*Buffer) DeleteWordLeft

func (b *Buffer) DeleteWordLeft()

DeleteWordLeft deletes the word before the cursor.

func (*Buffer) HistoryDown

func (b *Buffer) HistoryDown() bool

HistoryDown navigates down in history (newer entries).

func (*Buffer) HistoryUp

func (b *Buffer) HistoryUp() bool

HistoryUp navigates up in history (older entries).

func (*Buffer) Insert

func (b *Buffer) Insert(text string)

Insert inserts text at the current cursor position.

func (*Buffer) Line

func (b *Buffer) Line(row int) string

Line returns the text at the given row.

func (*Buffer) LineCount

func (b *Buffer) LineCount() int

LineCount returns the number of lines.

func (*Buffer) Lines

func (b *Buffer) Lines() []string

Lines returns all lines.

func (*Buffer) MoveDown

func (b *Buffer) MoveDown()

MoveDown moves the cursor down one line.

func (*Buffer) MoveLeft

func (b *Buffer) MoveLeft()

MoveLeft moves the cursor left by one character.

func (*Buffer) MoveRight

func (b *Buffer) MoveRight()

MoveRight moves the cursor right by one character.

func (*Buffer) MoveToEnd

func (b *Buffer) MoveToEnd()

MoveToEnd moves the cursor to the end of the line.

func (*Buffer) MoveToEndOfText

func (b *Buffer) MoveToEndOfText()

MoveToEndOfText moves the cursor to the end of the text.

func (*Buffer) MoveToStart

func (b *Buffer) MoveToStart()

MoveToStart moves the cursor to the start of the line.

func (*Buffer) MoveToStartOfText

func (b *Buffer) MoveToStartOfText()

MoveToStartOfText moves the cursor to the start of the text.

func (*Buffer) MoveUp

func (b *Buffer) MoveUp()

MoveUp moves the cursor up one line.

func (*Buffer) MoveWordLeft

func (b *Buffer) MoveWordLeft()

MoveWordLeft moves the cursor left by one word.

func (*Buffer) MoveWordRight

func (b *Buffer) MoveWordRight()

MoveWordRight moves the cursor right by one word.

func (*Buffer) NewLine

func (b *Buffer) NewLine()

NewLine inserts a newline at the cursor position.

func (*Buffer) Redo

func (b *Buffer) Redo() bool

Redo redoes the last undone action.

func (*Buffer) SetCursor

func (b *Buffer) SetCursor(row, col int)

SetCursor sets the cursor position.

func (*Buffer) SetCursorOffset

func (b *Buffer) SetCursorOffset(offset int)

SetCursorOffset sets the cursor from an offset.

func (*Buffer) SetText

func (b *Buffer) SetText(text string)

SetText sets the entire buffer content.

func (*Buffer) SetViewport

func (b *Buffer) SetViewport(height, width int)

SetViewport sets the viewport dimensions.

func (*Buffer) Text

func (b *Buffer) Text() string

Text returns the full text content.

func (*Buffer) Undo

func (b *Buffer) Undo() bool

Undo undoes the last action.

func (*Buffer) VisualLines

func (b *Buffer) VisualLines() []VisualLine

VisualLines returns the visible lines for rendering.

type EditAction

type EditAction struct {
	Type     ActionType
	Row, Col int
	Text     string
	PrevText string
}

EditAction represents an edit operation for undo/redo.

type VisualLine

type VisualLine struct {
	Row       int
	Text      string
	IsCursor  bool
	CursorCol int
}

VisualLine represents a line for visual rendering.

Jump to

Keyboard shortcuts

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