Table of Contents

Class TextAreaState

Namespace
MiniTui
Assembly
MiniTui.dll

The text and cursor of a multi-line text area (1.x spec §6). The text is a list of lines; the cursor is a line and a UTF-16 index that is always on a grapheme cluster boundary, so editing never splits a character.

public class TextAreaState
Inheritance
TextAreaState
Inherited Members

Constructors

TextAreaState(string)

Create a state with optional initial text. The cursor starts at the end.

public TextAreaState(string text = "")

Parameters

text string

Properties

AutoIndent

Enter starts the new line with the current line's indentation (1.x spec §16.3). Off by default.

public bool AutoIndent { get; set; }

Property Value

bool

CanRedo

True if Redo() has something to do again.

public bool CanRedo { get; }

Property Value

bool

CanUndo

True if Undo() has something to take back.

public bool CanUndo { get; }

Property Value

bool

Cursor

The cursor. Set values are clamped to the text and snap to the next cluster boundary, and clear the selection.

public TextPosition Cursor { get; set; }

Property Value

TextPosition

FindEnabled

Ctrl+F opens the find bar and F3 / Shift+F3 find again (1.x spec §16.5). On by default; turn it off to leave those keys to the app's bindings.

public bool FindEnabled { get; set; }

Property Value

bool

FindText

The text being found. Setting it searches again from the selection's start (or the cursor).

public string FindText { get; set; }

Property Value

string

HasSelection

True if some text is selected.

public bool HasSelection { get; }

Property Value

bool

IndentSize

The indent stop width: what Tab inserts with TabIndents, what Shift+Tab removes, and how far tabs in typed, set or pasted text expand. 4 by default, from 1 to 8. Changing it doesn't touch the text.

public int IndentSize { get; set; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

The value is outside 1–8.

IsFinding

True while the find bar is open: keys and pastes go to it (1.x spec §16.5).

public bool IsFinding { get; }

Property Value

bool

Lines

The lines, without line breaks. Never empty: empty text is one empty line.

public IReadOnlyList<string> Lines { get; }

Property Value

IReadOnlyList<string>

MatchCount

The number of matches of FindText in the text.

public int MatchCount { get; }

Property Value

int

MatchIndex

The index of the match that is the selection, or −1 when the selection isn't a match.

public int MatchIndex { get; }

Property Value

int

ScrollOffset

The first visible row (a wrapped row, not a line). Written by the widget while drawing, and by the wheel.

public int ScrollOffset { get; }

Property Value

int

SelectedText

The selected text, lines joined by "\n", or "".

public string SelectedText { get; }

Property Value

string

SelectionAnchor

The other end of the selection, or null for none; Cursor is the end that moves (1.x spec §10).

public TextPosition? SelectionAnchor { get; }

Property Value

TextPosition?

SelectionEnd

The end of the selection (the later of the anchor and the cursor), or the cursor without one.

public TextPosition SelectionEnd { get; }

Property Value

TextPosition

SelectionStart

The start of the selection (the earlier of the anchor and the cursor), or the cursor without one.

public TextPosition SelectionStart { get; }

Property Value

TextPosition

TabIndents

Tab and Shift+Tab indent and outdent instead of moving focus, and Backspace in a line's indentation deletes back to the previous indent stop (1.x spec §16.3). Off by default.

public bool TabIndents { get; set; }

Property Value

bool

Text

The text, lines joined by "\n". Setting it normalizes "\r\n" and "\r" to "\n", turns tabs into spaces up to the next multiple of IndentSize columns, removes other control characters, and moves the cursor to the end. Setting it also clears the selection and the undo history.

public string Text { get; set; }

Property Value

string

Methods

Clear()

Clear the text.

public void Clear()

ClearSelection()

Clear the selection, leaving the cursor where it is.

public void ClearSelection()

CloseFind()

Close the find bar, as Esc does. The current match stays selected, with the cursor at its end.

public void CloseFind()

Copy()

Copy the selection to the Clipboard.

public bool Copy()

Returns

bool

False, doing nothing, without a selection.

Cut()

Copy the selection to the Clipboard and delete it.

public bool Cut()

Returns

bool

False, doing nothing, without a selection.

FindNext()

Select the next match after the cursor, wrapping around the text.

public bool FindNext()

Returns

bool

False when there are no matches.

FindPrevious()

Select the previous match before the selection, wrapping around the text.

public bool FindPrevious()

Returns

bool

False when there are no matches.

HandleKey(ConsoleKeyInfo)

Handle an editing or movement key (1.x spec §6.3 and §10.3): text, Enter, ← → ↑ ↓, PgUp PgDn, Home End, Ctrl+Home End, Ctrl+← →, Shift with the movement keys to select, Backspace, Delete, Ctrl+Backspace / Ctrl+W, Ctrl+U, Ctrl+K, Ctrl+A (select all), Ctrl+C / Ctrl+X (copy and cut, only with a selection), Ctrl+V (paste the clipboard), Ctrl+Z (undo) and Ctrl+Y (redo), and with TabIndents, Tab and Shift+Tab (§16.3). Esc clears a selection; without one it isn't handled, nor are other Ctrl or Alt keys, nor Tab without TabIndents.

public virtual bool HandleKey(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

Returns

bool

True if the key was one of these.

HandleMouse(MouseEvent)

A left press inside the text moves the cursor there (Shift+press extends the selection to there), and a drag after it extends the selection, scrolling a row (or, without wrapping, a column) at a time past the edges; the wheel scrolls by three rows without moving the cursor (1.x spec §6.6 and §10.7). A double-click selects the word under the pointer and a triple-click its line (§17.4). Uses the area from the last draw.

public bool HandleMouse(MouseEvent mouse)

Parameters

mouse MouseEvent

Returns

bool

True if the event did any of these.

Insert(string)

Insert text at the cursor, replacing the selection, and move the cursor past it. Line breaks in the text start new lines.

public void Insert(string text)

Parameters

text string

OpenFind()

Open the find bar, as Ctrl+F does: it starts with the selection when that's within a line, or else the last find text, all selected so typing replaces it.

public void OpenFind()

Paste(string)

Insert pasted text at the cursor, replacing the selection and keeping the text's line breaks. Tabs and control characters are handled as for Text.

public bool Paste(string text)

Parameters

text string

Returns

bool

Always true, so a component can write HandlePaste(text) => State.Paste(text).

Redo()

Do again the last edit group undone.

public bool Redo()

Returns

bool

False when there's nothing to redo.

Select(TextPosition, TextPosition)

Select from anchor to cursor, both clamped and snapped as Cursor is. Equal values clear the selection.

public void Select(TextPosition anchor, TextPosition cursor)

Parameters

anchor TextPosition
cursor TextPosition

SelectAll()

Select all the text, with the cursor at the end.

public void SelectAll()

Undo()

Take back the last edit group (1.x spec §10.6): typed characters undo a word at a time. The text, cursor and selection return to how they were before it.

public bool Undo()

Returns

bool

False when there's nothing to undo.