Text

A multi-line text editor / display.

Live preview

An editable text area — type into it:

Live preview. In the Player's built-in docs viewer (scriptweaver --help), this renders Text as a live, theme-aware widget you can interact with.

Example

const t = app.Text({ wrap: 'word', undo: true });
t.pack.configure({ fill: 'both', expand: true });

t.setText('Hello\nworld');
t.insert('end', '\nmore');
console.log(t.getText());

Options

Option Type Description
wrap string 'word', 'char', or 'none'.
undo boolean Enable the built-in undo stack.
font string Text font.
width / height number Size in characters / lines.
state string 'normal' or 'disabled' (read-only).

Methods

Method Description
setText(s) / getText() Replace / read all the text.
insert(index, text) Insert at a text index.
delete(first, last?) Delete a range.
clear() Remove all text.
see(index) / index(idx) Scroll to / resolve an index.

Text indices are 'line.char' (1-based line, 0-based char), or keywords such as 'end' and 'insert' — e.g. '1.0' (start) or 'end-1c' (just before the trailing newline). Plus the inherited widget methods — see Widget basics.

Tags style ranges, marks name positions that drift with edits, search finds text, and you can embed images and child widgets — together these make the Text a small rich-text surface (it's what backs MarkView).

Method Description
tagConfigure(tag, opts) Style a tag (foreground, background, font, …).
tagAdd(tag, first, last) / tagRemove(tag, first, last) Apply / clear a tag over a range.
tagRanges(tag) The ranges a tag covers, as an array of indices.
tagRaise(tag[, above]) / tagLower(tag[, below]) Reorder a tag's priority.
tagDelete(...tags) Remove tags entirely.
tagBind(tag, seq, handler) Bind an event on a tag (e.g. a clickable link).
markSet(name, index) / markGravity(name[, dir]) Place a named marker / get-set its gravity ('left'/'right').
search(pattern, from?, to?, opts?) Find pattern; returns the first match index ('' if none), or — with { all: true } — an array of every match. opts: nocase, regexp, backwards, all.
imageCreate(index, photo, opts?) Embed a Photo at an index.
imageConfigure(name[, opts]) / imageNames() Reconfigure / list embedded images.
windowCreate(index, widget, opts?) Embed a child widget inline.
// Highlight every match of a search term.
for (const i of t.search('TODO', '1.0', 'end', { all: true })) {
  t.tagAdd('hit', i, `${i} +4c`);
}
t.tagConfigure('hit', { background: '#ffe082' });

See also