onCaretEvents([callback], [remove])

Class: TextArea. Method inherited from UIComponent.

Description:

Gets, registers or unregisters an event handler function for caret position changes and text selection changes in text editing components.

Parameters:

Name Type Default Description

[callback]

function

The event handler function that receives a CaretEvent object. Pass null to unregister all handler functions.

[remove]

boolean

false

Set to true to unregister the event handler.

Returns:

An array of handler functions if no arguments are passed, otherwise this component for method chaining.

Type: this | Array.<function()>

Examples:

// Example event object:
const e = {
  target: object,          // The component that triggered the event.
  type: string,            // `change`.
  position: number,        // New caret position
  selectionStart: number,  // Start position of selected text
  selectionEnd: number,    // End position of selected text
  line: number,            // Line of text where caret is now. Present only in some components, such as DocumentEditor.
  column: number,          // Position of caret from the beginning of the line where caret is now. Present only in multi-line text editing components, such as DocumentEditor.
  styles: object           // Text formatting information of the text segment where caret is now. Present only for DocumentEditor component when HTML is enabled.
  path: string[],          // HTML tag hierarchy. Present only for DocumentEditor component when HTML is enabled.
};

Also See: