Cursor Inspector

Reads text and HTML context around the caret for keyboard rules, formatting, and inline editing decisions.

Access:

app.getService('cursorInspector')

App code:

const cursorInspector = app.getService('cursorInspector');

Plugin:

const cursorInspector = this.app.getService('cursorInspector');

getTextBefore#

Returns up to length characters of plain text from the editor root start to the caret position.

Parameters:

  • length (any) — length

Returns: string

cursorInspector.getTextBefore(30);

getTextAfter#

Returns up to length characters of plain text from the caret to the end of the editor root.

Parameters:

  • length (any) — length

Returns: string

cursorInspector.getTextAfter(30);

getHtmlBefore#

Returns the HTML fragment from the start of the containing block to the caret position.

Returns: string

cursorInspector.getHtmlBefore();

getHtmlAfter#

Returns the HTML fragment from the caret to the end of the containing block.

Returns: string

cursorInspector.getHtmlAfter();

getSpaceAfter#

Detects whether the content immediately after the caret begins with a regular or invisible whitespace character.

Returns: { regularSpace: boolean, invisibleSpace: boolean }

cursorInspector.getSpaceAfter();

getSpaceBefore#

Detects whether the content immediately before the caret ends with a regular or invisible whitespace character.

Returns: { regularSpace: boolean, invisibleSpace: boolean }

cursorInspector.getSpaceBefore();

getBrOrInlineAfter#

Returns the first br or configured inline element at the start edge of the HTML after the caret, skipping whitespace text nodes.

Returns: HTMLElement|null

cursorInspector.getBrOrInlineAfter();

getBrOrInlineBefore#

Returns the last br or configured inline element at the end edge of the HTML before the caret, skipping whitespace text nodes.

Returns: HTMLElement|null

cursorInspector.getBrOrInlineBefore();