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 ¶
- type Buffer
- func (b *Buffer) Backspace()
- func (b *Buffer) Caret() Pos
- func (b *Buffer) Delete()
- func (b *Buffer) Insert(s string)
- func (b *Buffer) Line(i int) string
- func (b *Buffer) LineCount() int
- func (b *Buffer) MoveDown(extend bool) bool
- func (b *Buffer) MoveEnd(extend bool)
- func (b *Buffer) MoveHome(extend bool)
- func (b *Buffer) MoveLeft(extend bool)
- func (b *Buffer) MoveRight(extend bool)
- func (b *Buffer) MoveUp(extend bool) bool
- func (b *Buffer) SelectAll()
- func (b *Buffer) SelectedText() string
- func (b *Buffer) Selection() (start, end Pos, ok bool)
- func (b *Buffer) SetCaret(p Pos, extend bool)
- func (b *Buffer) SetText(s string)
- func (b *Buffer) Text() string
- type Pos
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 ¶
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) 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 ¶
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) MoveDown ¶
MoveDown moves the caret to the line below, like MoveUp. It reports false, and changes nothing, on the last line.
func (*Buffer) MoveLeft ¶
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 ¶
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 ¶
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 ¶
SelectedText returns the selected text, or "" when nothing is selected
func (*Buffer) Selection ¶
Selection returns the selected range in text order. ok is false when nothing is selected.
func (*Buffer) SetCaret ¶
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.