Skip to content

Commit

Permalink
Improve word boundries
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Dec 19, 2023
1 parent a585839 commit ea955f7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions package/src/extensions/search/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,18 @@ const highlightCurrentWord = (
return ([start, end], value) => {
if (start < end || !editor.focused || noHighlight) searchAPI.search("")
else {
let group = `[\\p{L}_$\\d${includeHyphens && includeHyphens(start) ? "-" : ""}]*`
let before = value.slice(0, start).match(RegExp(group + "$", "u"))!
let group = `[_$\\p{L}\\d${includeHyphens && includeHyphens(start) ? "-" : ""}]`
let before = value.slice(0, start).match(RegExp(group + "*$", "u"))!
let index = before.index!
let word = before[0] + value.slice(start).match(RegExp("^" + group, "u"))![0]
let word = before[0] + value.slice(start).match(RegExp("^" + group + "*", "u"))![0]
searchAPI.search(
/^-*(\d|$)/.test(word) || (filter && !filter(index, index + word.length)) ? "" : word,
true,
true,
false,
undefined,
filter,
RegExp(group + "{2}", "u"),
)
}
noHighlight = false
Expand Down

0 comments on commit ea955f7

Please sign in to comment.