selectionMatch ignores surrounding whitespace

When CodeMirror highlights selection matches it ignores surrounding whitespace in the selection.

Given the text

// foobarbaz
// foobar
// barbaz

if you select the entire last line, any occurrence of “bar” in the previous lines will be highlighted despite having a different prefix and suffix:

vscode for comparison considers the whitespace:

Is the CodeMirror behavior by design? If yes, is there an option to only highlight exact matches?

Where that came from is lost to git history (it was already there in the patch that moves this code into @codemirror/search), but I don’t see a particularly good reason for it to work this way, so this patch removes it.

1 Like