selection([start], [end])

Class: TextArea. Method inherited from TextComponent.

Description:

Selects text at specified position and length or gets current selection as an object {start:number, length:number, text:string}.

Parameters:

Name Type Description

[start]

number

Beginning position of text to be selected.

[end]

number

End position of text to be selected. If start argument is provided but end is omitted, end will be same as start, simply placing cursor at the start position.

Returns:

If arguments are provided, this TextField component is returned; otherwise current selection is returned as object {start:number, end:number, text:string}.

Type: Object | this

Examples:

// Setting selection
textfield.selection(10, 30);
// getting selection
let s = textfield.selection();
console.log(`Selected from ${s.start} to ${s.end}: ${s.text}`);