Canvas Toolkit
← Class index

CTextDocument

GUI and styling

Stores plain text together with character-format ranges.

Module gui/CTextDocument.js. This class is available through the browser modules in the download.

Declared members

constructor(text?: string);

Creates a new CTextDocument instance. @param text Text.

toPlainText(): string;

Returns the document contents as plain text. @returns The resulting value.

length(): number;

Returns the number of characters in the document. @returns The resulting value.

clone(): CTextDocument;

Creates an independent copy of this object. @returns The resulting value.

setPlainText(text: string): void;

Replaces the document contents with plain text. @param text Text.

clear(): void;

Clears the current contents.

formatRanges(): readonly CTextFormatRange[];

Returns the character-format ranges in the document. @returns The resulting value.

charFormatAt(position: number): CTextCharFormat;

Returns the character format at the specified position. @param position Position. @returns The resulting value.

insert(position: number, text: string, format?: CTextCharFormat | null): void;

Inserts text at the specified position. @param position Position. @param text Text. @param format Format.

remove(start: number, length: number): void;

Removes a range of text from the document. @param start Start. @param length Length.

setCharFormat(start: number, length: number, format: CTextCharFormat): void;

Applies a character format to a range of text. @param start Start. @param length Length. @param format Format.