Skip to content

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.

csharp
public class TextBoxState

Inheritance ​

Object → TextBoxState

Constructors ​

TextBoxState() ​

Creates an empty text box state with the cursor at offset zero.

csharp
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. A null value is treated as an empty string.
csharp
public TextBoxState(string initialText)

Properties ​

CursorPosition ​

Returns: Int32

csharp
public int CursorPosition { get; set; }

HasSelection ​

Returns true if there is an active text selection.

Returns: Boolean

csharp
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

csharp
public bool IsMultiline { get; set; }

MaxLines ​

Maximum number of lines allowed in multiline mode. When null, there is no limit.

Returns: Nullable<Int32>

csharp
public int? MaxLines { get; set; }

SelectedText ​

Gets the selected text.

Returns: String

csharp
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>

csharp
public int? SelectionAnchor { get; set; }

SelectionEnd ​

Gets the end index of the selection (exclusive).

Returns: Int32

csharp
public int SelectionEnd { get; }

SelectionStart ​

Gets the start index of the selection (inclusive).

Returns: Int32

csharp
public int SelectionStart { get; }

Text ​

Returns: String

csharp
public string Text { get; set; }

Methods ​

ClearSelection() ​

Clears the current selection.

csharp
public void ClearSelection()

GetLineCount() ​

Returns the number of lines in the text (1-based; empty string has 1 line).

Returns: Int32

csharp
public int GetLineCount()

GetLineLength(int) ​

Returns the length of the given 0-based line (excluding the newline character).

Parameters:

Returns: Int32

csharp
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:

Returns: Int32

csharp
public int GetLineStartOffset(int line)

GetLineText(int) ​

Gets the text content of the given 0-based line (excluding newline).

Parameters:

Returns: String

csharp
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:

Returns: Boolean

csharp
public bool HandleInput(Hex1bKeyEvent evt)

InsertNewline() ​

Inserts a newline at the current cursor position.

csharp
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

csharp
public int LineColumnToOffset(int line, int column)

MoveDown(bool) ​

Moves the cursor down one line, preserving the preferred column.

Parameters:

csharp
public void MoveDown(bool extend = false)

MoveUp(bool) ​

Moves the cursor up one line, preserving the preferred column.

Parameters:

csharp
public void MoveUp(bool extend = false)

OffsetToLineColumn(int) ​

Converts a flat cursor offset to a (line, column) pair (both 0-based).

Parameters:

Returns: ValueTuple<Int32, Int32>

csharp
public (int line, int column) OffsetToLineColumn(int offset)

SelectAll() ​

Selects all text.

csharp
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.

Released under the MIT License.