TextBoxState
Namespace: Hex1b.Widgets
Assembly: Hex1b.dll
Mutable state object for a . Owns the text buffer, the cursor position, the optional selection anchor, and the multiline / line limits configured through the widget.
public class TextBoxStateInheritance
Object → TextBoxState
Constructors
TextBoxState()
Creates an empty text box state with the cursor at offset zero.
public TextBoxState()TextBoxState(string)
Creates a text box state seeded with initialText. The cursor is positioned at the end of the supplied text and there is no active selection.
Parameters:
initialText(String): The initial text to populate the buffer with. Anullvalue is treated as an empty string.
public TextBoxState(string initialText)Properties
CursorPosition
Returns: Int32
public int CursorPosition { get; set; }HasSelection
Returns true if there is an active text selection.
Returns: Boolean
public bool HasSelection { get; }IsMultiline
When true, the text box operates in multi-line mode. Enter inserts newlines, Up/Down navigate between lines, Home/End operate on the current line.
Returns: Boolean
public bool IsMultiline { get; set; }MaxLines
Maximum number of lines allowed in multiline mode. When null, there is no limit.
Returns: Nullable<Int32>
public int? MaxLines { get; set; }SelectedText
Gets the selected text.
Returns: String
public string SelectedText { get; }SelectionAnchor
The anchor position for text selection. If null, no selection is active. Selection range is from min(SelectionAnchor, CursorPosition) to max(SelectionAnchor, CursorPosition).
Returns: Nullable<Int32>
public int? SelectionAnchor { get; set; }SelectionEnd
Gets the end index of the selection (exclusive).
Returns: Int32
public int SelectionEnd { get; }SelectionStart
Gets the start index of the selection (inclusive).
Returns: Int32
public int SelectionStart { get; }Text
Returns: String
public string Text { get; set; }Methods
ClearSelection()
Clears the current selection.
public void ClearSelection()GetLineCount()
Returns the number of lines in the text (1-based; empty string has 1 line).
Returns: Int32
public int GetLineCount()GetLineLength(int)
Returns the length of the given 0-based line (excluding the newline character).
Parameters:
line(Int32):
Returns: Int32
public int GetLineLength(int line)GetLineStartOffset(int)
Returns the flat offset where the given 0-based line starts. Line 0 starts at offset 0.
Parameters:
line(Int32):
Returns: Int32
public int GetLineStartOffset(int line)GetLineText(int)
Gets the text content of the given 0-based line (excluding newline).
Parameters:
line(Int32):
Returns: String
public string GetLineText(int line)HandleInput(Hex1bKeyEvent)
Handles keyboard input for the text box. Returns true if the input was handled, false if it should be passed to parent containers.
Parameters:
evt(Hex1bKeyEvent):
Returns: Boolean
public bool HandleInput(Hex1bKeyEvent evt)InsertNewline()
Inserts a newline at the current cursor position.
public void InsertNewline()LineColumnToOffset(int, int)
Converts a (line, column) pair (both 0-based) to a flat cursor offset. Column is clamped to the line's length.
Parameters:
Returns: Int32
public int LineColumnToOffset(int line, int column)MoveDown(bool)
Moves the cursor down one line, preserving the preferred column.
Parameters:
extend(Boolean):
public void MoveDown(bool extend = false)MoveUp(bool)
Moves the cursor up one line, preserving the preferred column.
Parameters:
extend(Boolean):
public void MoveUp(bool extend = false)OffsetToLineColumn(int)
Converts a flat cursor offset to a (line, column) pair (both 0-based).
Parameters:
offset(Int32):
Returns: ValueTuple<Int32, Int32>
public (int line, int column) OffsetToLineColumn(int offset)SelectAll()
Selects all text.
public void SelectAll()Remarks
A can be created and managed inside a composite via and routed into a with . When state is supplied this way, the textbox becomes a pure view of the instance — the parent can mutate directly and the change is reflected on the next reconcile, without an OnTextChanged shadow-sync handler.
When the parent does not supply a state instance, the framework allocates one per node automatically and seeds it from the widget's constructor argument.