highlightCurrentWord
highlightCurrentWord(
filter?
,includeHyphens?
):WordHighlighter
Defined in: extensions/search/selection.ts:78
Extension that highlights all instances of the word the cursor is on if there’s no selection.
Parameters
Section titled “Parameters”filter?
Section titled “filter?”Function that can filter away matches based on their position.
The filter can be changed later using the setFilter
method.
includeHyphens?
Section titled “includeHyphens?”(cursorPosition
) => boolean
A function returning whether or not hyphens should be included in the search. For languages that don’t commonly use hyphens as an operator (such as CSS), it makes sense to return true. If this parameter is omitted, hyphens are not included.
The CSS-selector .word-matches span
can be used to style the matches.
Returns
Section titled “Returns”Example
Section titled “Example”This filters away all words that start inside a string, comment or keyword or regex token. Different filter functions should be chosen based on the language.
const selector = ".string, .comment, .keyword, .regex"const filter = start => !getClosestToken(editor, selector, 0, 0, start)const includeHyphens = position => getLanguage(editor, position) == "css"
editor.addExtensions( highlightCurrentWord(filter, includeHyphens))