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/mw_games/two-d/ui';

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

      what to draw for a password field: every character replaced by the mask

      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

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

      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