textedit

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package textedit holds the text, caret, and selection of a multi-line text field, with the editing operations on them. It has no drawing or input handling, so a widget maps keys and mouse positions onto it.

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 the text of a multi-line field with its caret and selection. The selection runs from the anchor to the caret and is empty when they are equal. There is always at least one line: an empty text is one empty line.

func New

func New(maxRunes, maxLines int) *Buffer

New creates an empty buffer. maxRunes caps the text length, counting each line break as one rune, and maxLines caps the line count. Zero means no limit.

func (*Buffer) Backspace

func (b *Buffer) Backspace()

Backspace deletes the selection, or the rune before the caret, joining the line with the one above at the start of a line

func (*Buffer) Caret

func (b *Buffer) Caret() Pos

Caret returns the caret position

func (*Buffer) Delete

func (b *Buffer) Delete()

Delete deletes the selection, or the rune after the caret, joining the next line at the end of a line

func (*Buffer) Insert

func (b *Buffer) Insert(s string)

Insert replaces the selection with s, or inserts s at the caret. "\r\n" and "\r" become line breaks, tabs become spaces, and other control characters are dropped. Only the part of s that fits the limits is inserted.

func (*Buffer) Line

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

Line returns line i

func (*Buffer) LineCount

func (b *Buffer) LineCount() int

LineCount returns the number of lines, at least 1

func (*Buffer) MoveDown

func (b *Buffer) MoveDown(extend bool) bool

MoveDown moves the caret to the line below, like MoveUp. It reports false, and changes nothing, on the last line.

func (*Buffer) MoveEnd

func (b *Buffer) MoveEnd(extend bool)

MoveEnd moves the caret to the end of its line

func (*Buffer) MoveHome

func (b *Buffer) MoveHome(extend bool)

MoveHome moves the caret to the start of its line

func (*Buffer) MoveLeft

func (b *Buffer) MoveLeft(extend bool)

MoveLeft moves the caret one rune left, to the end of the line above at the start of a line. Without extend a selection collapses to its start instead.

func (*Buffer) MoveRight

func (b *Buffer) MoveRight(extend bool)

MoveRight moves the caret one rune right, to the start of the next line at the end of a line. Without extend a selection collapses to its end instead.

func (*Buffer) MoveUp

func (b *Buffer) MoveUp(extend bool) bool

MoveUp moves the caret to the line above, at the column it was last placed on or the end of that line if shorter. It reports false, and changes nothing, on the first line.

func (*Buffer) SelectAll

func (b *Buffer) SelectAll()

SelectAll selects the whole text, leaving the caret at the end

func (*Buffer) SelectedText

func (b *Buffer) SelectedText() string

SelectedText returns the selected text, or "" when nothing is selected

func (*Buffer) Selection

func (b *Buffer) Selection() (start, end Pos, ok bool)

Selection returns the selected range in text order. ok is false when nothing is selected.

func (*Buffer) SetCaret

func (b *Buffer) SetCaret(p Pos, extend bool)

SetCaret moves the caret to p, clamped into the text. With extend the selection grows from its anchor to p; without, the selection is cleared.

func (*Buffer) SetText

func (b *Buffer) SetText(s string)

SetText replaces the text, keeping what fits the limits, and puts the caret at the end with no selection

func (*Buffer) Text

func (b *Buffer) Text() string

Text returns the text with lines joined by "\n"

type Pos

type Pos struct {
	Line int
	Col  int
}

Pos is a position in the text: a line index and a column, both counted in runes. A column equal to the line length is the end of the line.

Jump to

Keyboard shortcuts

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