Canvas Toolkit
← Class index

CTextEdit

Widgets · extends CScrollArea

Implements the text edit widget.

import { CTextEdit } from "canvas-toolkit-lib";

Declared members

readonly textChanged: CSignal<[]>;

Signal emitted when text changes.

readonly selectionChanged: CSignal<[]>;

Signal emitted when selection changes.

readonly undoAvailable: CSignal<[boolean]>;

Emitted only when undo availability changes.

readonly redoAvailable: CSignal<[boolean]>;

Emitted only when redo availability changes.

constructor(parent?: CWidget | null);

Creates a new instance.

toPlainText(): string;

Provides to plain text behavior.

toHtml(): string;

Provides to html behavior.

setHtml(html: string): void;

Sets the html.

find(text: string, flags?: CTextEditFindFlag): boolean;

Selects the next literal match, starting after the current selection (before it for Backward). Searches do not wrap. Returns false without changing cursor or selection when the query is empty or no match exists. Read-only documents can be searched; document contents and undo history are never modified.

replace(text: string, replacement: string, flags?: CTextEditFindFlag): boolean;

Replaces a matching current selection, otherwise the next match in the requested direction. Returns false when read-only or no match exists. Replacement text is literal and inherits the match's first character format.

replaceAll(text: string, replacement: string, flags?: CTextEditFindFlag): number;

Replaces non-overlapping matches in the entire document and returns their count. Backward is ignored. One undo restores the entire operation. Empty queries and read-only documents return zero without changing state.

setPlainText(text: string): void;

Sets the plain text.

placeholderText(): string;
setPlaceholderText(text: string): void;
clear(): void;

Clears the current contents.

isReadOnly(): boolean;

Returns whether the read only condition is active.

setReadOnly(readOnly?: boolean): void;

Sets the read only.

cursor(): CCursorShape;

Provides cursor behavior.

cursorPosition(): number;

Provides cursor position behavior.

setCursorPosition(position: number): void;

Sets the cursor position.

cursorVisible(): boolean;

Provides cursor visible behavior.

selectionStart(): number;

Provides selection start behavior.

selectionEnd(): number;

Provides selection end behavior.

hasSelection(): boolean;

Returns whether this object has selection.

selectedText(): string;

Returns the selected text.

setSelection(anchor: number, position: number): void;

Sets the selection.

clearSelection(): void;

Clears selection.

selectAll(): void;

Provides select all behavior.

insert(text: string): void;

Inserts .

nativeTextState(): {
        text: string;
        start: number;
        end: number;
    } | null;

@internal Supplies the browser input context for the focused editor.

applyNativeTextUpdate(start: number, end: number, text: string): void;

@internal Applies the replacement reported by the browser input context.

protected supportsRichText(): boolean;

Handles text document behavior. Whether character formatting is supported by this editor.

protected textDocument(): CTextDocument;
currentCharFormat(): CTextCharFormat;

Returns the current char format.

setCurrentCharFormat(format: CTextCharFormat): void;

Sets the current char format.

setFontBold(bold: boolean): void;

Sets the font bold.

setFontItalic(italic: boolean): void;

Sets the font italic.

setFontUnderline(underline: boolean): void;

Sets the font underline.

setTextColor(color: string | null): void;

Sets the text color.

setFontFamily(family: string | null): void;

Sets the font family.

setFontSize(size: number | null): void;

Sets the font size.

canUndo(): boolean;

Returns whether undo is currently possible.

canRedo(): boolean;

Returns whether redo is currently possible.

undo(): void;

Provides undo behavior.

redo(): void;

Reapplies the next edit and restores its cursor, selection and formatting.

copy(): void;

Provides copy behavior.

cut(): void;

Provides cut behavior.

paste(): void;

Provides paste behavior.

pasteFromSystem(): Promise<void>;

Reads the system clipboard for a user-invoked Paste command.

sizeHint(): CSize;

Returns the preferred size of the widget.

setGeometry(x: number, y: number, width: number, height: number): void;

Sets the geometry.

resize(width: number, height: number): void;

Provides resize behavior.

protected textPositionAt(x: number, y: number): number;

Handles text position at behavior.

protected textCharFormatAt(x: number, y: number): CTextCharFormat | null;

Handles text char format at behavior.

paintText(painter: CPainter): void;

Provides paint text behavior.

handleMousePress(event: CMouseEvent): void;

Provides handle mouse press behavior.

handleMouseDoubleClick(event: CMouseEvent): void;

Handles a double-click forwarded by the content widget.

handleMouseMove(event: CMouseEvent): void;

Provides handle mouse move behavior.

handleMouseRelease(event: CMouseEvent): void;

Provides handle mouse release behavior.

protected keyPressEvent(event: CKeyEvent): void;

Handles the key press event.

protected focusInEvent(event: CFocusEvent): void;

Handles the focus in event.

protected focusOutEvent(event: CFocusEvent): void;

Handles the focus out event.

handleContextMenu(event: CContextMenuEvent): void;

Forwards context requests from the scroll area's content widget.

createStandardContextMenu(): CMenu;

Creates a menu using the current editor state. The caller owns the returned menu and must destroy it after use.

protected contextMenuEvent(event: CContextMenuEvent): void;
destroy(): void;