Phosphor::TextAreaMock
Inherits Phosphor::MockWidget < Reference < Object
A multi-line text input primitive.
Generic and app-agnostic: no knowledge of AppState, Msg, or the
application theme. The Widget wrapper resolves theme → Style values
and sets them in Props before each render. Extends InputMock's
conventions to multiple rows: the cursor position and vertical scroll
offset are owned by this widget's WidgetState; the text lives in
props.lines and is updated by Cmd::InsertChar / Cmd::DeleteChar.
Reuses Cmd::MoveUp / Cmd::MoveDown (from ListMock) and
Cmd::MoveCursorLeft / Cmd::MoveCursorRight / Cmd::InsertChar /
Cmd::DeleteChar (from InputMock) — each Cmd is a generic token;
TextAreaMock interprets it with row/column-clamping semantics instead
of ListMock's wrap-around semantics.
Constructors
Initialises the text area with props and an optional state.
Instance methods
Responds to cursor-movement and editing commands.
Cmd::MoveCursorLeft—cursor_col− 1; wraps to the end of the previous line when already at column 0.Cmd::MoveCursorRight—cursor_col+ 1; wraps to the start of the next line when already at the end of the line.Cmd::MoveUp—cursor_row− 1, clamped at 0;cursor_colis clamped to the new line's length.Cmd::MoveDown—cursor_row+ 1, clamped at the last line;cursor_colis clamped to the new line's length.Cmd::InsertChar— inserts the character atcursor_colon the current line, then advancescursor_col.Cmd::InsertString— inserts the full string atcursor_row/cursor_colin one operation, then advancescursor_colby its length. Typically built from theDataEventaCmd::Pasteproduces, so a pasted block never triggers one re-render per character. Inserted directly into the current line — embedded newlines are not split into new rows.Cmd::DeleteChar— deletes the character beforecursor_col. At column 0, merges the current line into the previous one instead. ReturnsCmdResult::Noneat row 0, column 0 — nothing to delete.- Any other command, or an empty
props.lines— returnsCmdResult::None.
Every branch that moves the cursor also re-clamps scroll_row against
the most recently rendered frame height, if any, so state.scroll_row
stays correct even when inspected before the next render.
Renders the visible window of props.lines into buf within frame.
scroll_row is adjusted first so cursor_row is visible, then up to
frame.height lines starting at scroll_row are drawn. When
props.line_number_style is set, each line is preceded by a
right-aligned line number wide enough for the largest number in
props.lines, plus one column of padding; the text itself is
truncated to whatever width remains via max_width. The character at
cursor_row/cursor_col is overlaid with props.cursor_style.
Narrows the inherited state getter to TextAreaMock::WidgetState.
Safe: initialize only ever stores a WidgetState into the base
@state ivar.