Skip to content

getClosestToken

getClosestToken(editor, selector, marginLeft, marginRight, position): HTMLSpanElement | undefined

Defined in: utils/index.ts:60

Searches a full line for a token that matches a selector and contains position within the specified margins. Tokens are searched in reverse document order which means children are searched before their parents.

PrismEditor

Editor you want to search in.

string

CSS selector for the tokens you want to search for.

number = 0

How far to the left of the token the position can be. Defaults to 0.

number = marginLeft

How far to the right of the token the position can be. Defaults to marginLeft.

number = ...

Position to search in. Defaults to selectionStart.

HTMLSpanElement | undefined

A span element if one’s found or undefined if not.

This will return a string token if the cursor is at least 1 character inside a string token

getClosestToken(editor, '.string', -1)