mwg API
    Preparing search index...

    Class TextModel

    The editing state behind a text field, with no renderer attached - the counterpart to core.Input's onText, which supplies the characters: the DOM gives a key, this decides where it goes, and a game draws value (or maskedValue) with the caret it reports.

    The caret is an index into value; a selection is the caret plus an anchor, so every edit replaces the selection when there is one and inserts at the caret when there is not, which is the behaviour a plain <input> has and a title screen's name entry expects.

    import { TextModel } from '@datamoc/mwg/two-d/ui';

    const name = new TextModel({ maxLength: 8, value: 'Hero' });
    name.selectAll();
    name.insert('Ash');
    console.log(name.value); // 'Ash'
    Index
    • get lineCount(): number

      rows in a multiline field; always 1 for a single-line one, even when empty

      Returns number

    • get maskedValue(): string

      what to draw for a password field: every character replaced by the mask, except newlines, which stay newlines so a masked multiline value keeps its rows

      Returns string

    • the backspace key: removes the selection, or the character before the caret

      Returns void

    • the delete key: removes the selection, or the character after the caret

      Returns void

    • inserts at the caret, replacing the selection, as a keystroke from onText does

      Parameters

      • text: string

      Returns void

    • [start, end) of a row, the end stopping before its newline; out-of-range rows clamp

      Parameters

      • line: number

      Returns readonly [number, number]

    • arrow keys: moves the caret, extending the selection when the shift key is held

      Parameters

      • delta: number
      • extend: boolean = false

      Returns void

    • Up/down between rows, holding the column: the caret lands as far along the new row as it goes, the way a <textarea> moves. Rows here are newline-delimited, since only the renderer knows where a long row wraps on screen.

      Parameters

      • delta: number
      • extend: boolean = false

      Returns void

    • replaces the selection (or inserts at the caret) and leaves the caret after the new text

      Parameters

      • text: string

      Returns void

    • Parameters

      • index: number
      • extend: boolean = false

      Returns void

    • replaces everything; the caret goes to the end and a new string is never longer than maxLength

      Parameters

      • value: string

      Returns void