Reference Source
import SuperTextarea from 'flarum/utils/SuperTextarea'
public class | source

SuperTextarea

A textarea wrapper with powerful helpers for text manipulation.

This wraps a <textarea> DOM element and allows directly manipulating its text contents and cursor positions.

I apologize for the pretentious name. :)

Constructor Summary

Public Constructor
public

constructor(textarea: HTMLTextAreaElement)

Member Summary

Public Members
public

$: *

public

el: *

Method Summary

Public Methods
public

Get the selected range of the textarea.

public

insertAt(pos: number, text: String)

Insert content into the textarea at the given position.

public

Insert content into the textarea at the position of the cursor.

public

insertBetween(start: *, end: *, text: *)

Insert content into the textarea between the given positions.

public

moveCursorTo(position: number)

Focus the textarea and place the cursor at the given index.

public

replaceBeforeCursor(start: *, text: *)

Replace existing content from the start to the current cursor position.

public

setValue(value: String)

Set the value of the text editor.

Private Methods
private

Set the selected range of the textarea.

Public Constructors

public constructor(textarea: HTMLTextAreaElement) source

Params:

NameTypeAttributeDescription
textarea HTMLTextAreaElement

Public Members

public $: * source

public el: * source

Public Methods

public getSelectionRange(): Array source

Get the selected range of the textarea.

Return:

Array

public insertAt(pos: number, text: String) source

Insert content into the textarea at the given position.

Params:

NameTypeAttributeDescription
pos number
text String

public insertAtCursor(text: String) source

Insert content into the textarea at the position of the cursor.

Params:

NameTypeAttributeDescription
text String

public insertBetween(start: *, end: *, text: *) source

Insert content into the textarea between the given positions.

If the start and end positions are different, any text between them will be overwritten.

Params:

NameTypeAttributeDescription
start *
end *
text *

public moveCursorTo(position: number) source

Focus the textarea and place the cursor at the given index.

Params:

NameTypeAttributeDescription
position number

public replaceBeforeCursor(start: *, text: *) source

Replace existing content from the start to the current cursor position.

Params:

NameTypeAttributeDescription
start *
text *

public setValue(value: String) source

Set the value of the text editor.

Params:

NameTypeAttributeDescription
value String

Private Methods

private setSelectionRange(start: number, end: number) source

Set the selected range of the textarea.

Params:

NameTypeAttributeDescription
start number
end number