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.
Parameters
Section titled “Parameters”editor
Section titled “editor”Editor you want to search in.
selector
Section titled “selector”string
CSS selector for the tokens you want to search for.
marginLeft
Section titled “marginLeft”number = 0
How far to the left of the token the position can be. Defaults to 0.
marginRight
Section titled “marginRight”number = marginLeft
How far to the right of the token the position can be. Defaults to marginLeft.
position
Section titled “position”number = ...
Position to search in. Defaults to selectionStart.
Returns
Section titled “Returns”HTMLSpanElement | undefined
A span element if one’s found or undefined if not.
Example
Section titled “Example”This will return a string token if the cursor is at least 1 character inside a string token
getClosestToken(editor, '.string', -1)