lineedit

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lineedit is the one-line text editor behind every text field of the UI. It depends on nothing in package ui, so components in their own packages can edit the shared line.

Index

Constants

View Source
const Indent = 2

Indent is how far a wrapped line's continuation rows are indented.

Variables

This section is empty.

Functions

func Caret added in v0.3.0

func Caret(rows []Row, buf []rune, pos int) (row, col int)

Caret is the row the caret is on among rows, and its column there, continuation rows' indent included.

func IsWordKey added in v0.3.0

func IsWordKey(key string) bool

IsWordKey reports whether key moves or deletes by word or to the start of the line, so a field can pass it on to Key.

func RowWidth added in v0.3.0

func RowWidth(buf []rune, from, to int) int

RowWidth is the columns buf[from:to] takes.

func Typed

func Typed(k tea.KeyPressMsg) string

Typed returns the printable text of a key press, if any.

Types

type Area added in v0.3.0

type Area struct {
	Line
	// contains filtered or unexported fields
}

Area is the multi-line editor of a notebook's cells: Line's text and caret, with line breaks, soft-wrapped to a width so no text is ever hidden. A line longer than the width breaks before a pipe (|) where it can, then after a space, then anywhere; the rows it continues on are indented by Indent. Up and Down, Home and End move by those rows.

func (*Area) InsertText added in v0.3.0

func (a *Area) InsertText(text string)

InsertText types text at the caret, line breaks included; a tab is two spaces, and other control characters are dropped.

func (*Area) Key added in v0.3.0

func (a *Area) Key(k tea.KeyPressMsg, width int) bool

Key applies an editing key at width, reporting whether it was one. Enter breaks the line, keeping its indent.

func (*Area) Offset added in v0.3.0

func (a *Area) Offset() int

Offset is the caret as a byte offset into the text, what a completer or checker is given.

func (*Area) Place added in v0.3.0

func (a *Area) Place(width, row, col int)

Place puts the caret nearest column col of row row of the text wrapped at width, as a click there does.

func (*Area) SetText added in v0.3.0

func (a *Area) SetText(text string)

SetText replaces the text, with the caret at its end.

type Line

type Line struct {
	Buf []rune
	Pos int // the caret, an index into Buf
}

Line is the one-line text editor behind every text field: the entry typed into a cell (ENTER, EDIT), prompts on the context line, and the search fields of the find bar and the pickers. Only one of them is edited at a time, so they share it; a component with several fields keeps the others' text itself and loads a field here to edit it.

func (*Line) CanPoint

func (l *Line) CanPoint() bool

CanPoint reports whether the text before the caret ends where a cell reference may follow.

func (*Line) Clear

func (l *Line) Clear()

Clear empties the line.

func (*Line) DeleteBack added in v0.3.0

func (l *Line) DeleteBack(from int)

DeleteBack deletes from index from up to the caret.

func (*Line) Head

func (l *Line) Head() string

Head and tail are the text before and after the caret.

func (*Line) Insert

func (l *Line) Insert(text string)

Insert types text at the caret. Line breaks and tabs become spaces, and other control characters are dropped.

func (*Line) IsFormula

func (l *Line) IsFormula() bool

IsFormula reports whether the edit line holds a formula.

func (*Line) Key

func (l *Line) Key(k tea.KeyPressMsg)

Key applies a line-editing Key.

func (*Line) Set

func (l *Line) Set(text string)

Set replaces the text, with the caret at its end.

func (*Line) SetCaret

func (l *Line) SetCaret(x int)

SetCaret puts the edit caret at display column x of the entry.

func (*Line) Tail

func (l *Line) Tail() string

func (*Line) Text

func (l *Line) Text() string

Text is the whole line.

type Row added in v0.3.0

type Row struct {
	Start, End int
	Cont       bool
}

Row is one row of wrapped text: Buf[Start:End], a continuation of the row before it (drawn Indent further in) when Cont is set.

func Wrap added in v0.3.0

func Wrap(buf []rune, width int) []Row

Wrap lays buf out in rows at most width columns wide.

Jump to

Keyboard shortcuts

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