Class TextFieldState
- Namespace
- MiniTui
- Assembly
- MiniTui.dll
The text and cursor of a single-line text field (§8.4). The cursor is a UTF-16 index that is always on a grapheme cluster boundary, so editing never splits a character.
public class TextFieldState
- Inheritance
-
TextFieldState
- Derived
- Inherited Members
Constructors
TextFieldState(string)
Create a state with optional initial text. The cursor starts at the end.
public TextFieldState(string text = "")
Parameters
textstring
Properties
CanRedo
True if Redo() has something to do again.
public bool CanRedo { get; }
Property Value
CanUndo
True if Undo() has something to take back.
public bool CanUndo { get; }
Property Value
Cursor
The cursor as a UTF-16 index into Text. Set values snap to the next cluster boundary, and clear the selection.
public int Cursor { get; set; }
Property Value
HasSelection
True if some text is selected.
public bool HasSelection { get; }
Property Value
ScrollOffset
The first visible display column. Written by the widget while drawing.
public int ScrollOffset { get; }
Property Value
SelectedText
The selected text, or "".
public string SelectedText { get; }
Property Value
SelectionAnchor
The other end of the selection, or null for none; Cursor is the end that moves (1.x spec §10).
public int? SelectionAnchor { get; }
Property Value
- int?
SelectionEnd
The end of the selection (the higher of the anchor and the cursor), or the cursor without one.
public int SelectionEnd { get; }
Property Value
SelectionStart
The start of the selection (the lower of the anchor and the cursor), or the cursor without one.
public int SelectionStart { get; }
Property Value
Text
The text. Setting it moves the cursor to the end, and clears the selection and the undo history.
public string Text { get; set; }
Property Value
Methods
Clear()
Clear the text.
public void Clear()
ClearSelection()
Clear the selection, leaving the cursor where it is.
public void ClearSelection()
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.
HandleKey(ConsoleKeyInfo)
Handle an editing key (§8.4 and 1.x spec §10.3): text, ← → Home End, Ctrl+← →, Shift with those to select, Backspace, Delete, Ctrl+Backspace / Ctrl+W (delete word), Ctrl+U (delete to start), Ctrl+K (delete to end), Ctrl+A (select all), Ctrl+C / Ctrl+X (copy and cut, only with a selection), Ctrl+V (paste the clipboard), Ctrl+Z (undo), Ctrl+Y (redo) and Esc (clear the selection, only with one).
public virtual bool HandleKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo
Returns
- bool
True if the key was an editing key.
HandleMouse(MouseEvent)
A left press in the text moves the cursor there (Shift+press extends the selection to there), and a drag after it extends the selection, scrolling a column at a time past either edge (1.x spec §10.7). A double-click selects the word under the pointer and a triple-click all the text (§17.4). Uses the area from the last draw.
public bool HandleMouse(MouseEvent mouse)
Parameters
mouseMouseEvent
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.
public void Insert(string text)
Parameters
textstring
Paste(string)
Insert pasted text at the cursor, replacing the selection. Leading and trailing line breaks are dropped, each other line break and each tab becomes a space, and other control characters are removed, so a multi-line paste becomes one line.
public bool Paste(string text)
Parameters
textstring
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(int, int)
Select from anchor to cursor, both clamped and snapped as
Cursor is. Equal values clear the selection.
public void Select(int anchor, int cursor)
Parameters
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.