Skip to content

Commit

Permalink
Improve search
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Nov 16, 2023
1 parent 922bfeb commit 5fa8c2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package/src/extensions/search/search.css
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,6 @@ button.pce-whole {
}

.pce-matches :empty {
box-shadow: 0 0 0 2px var(--search__bg-find);
padding: 0 2px;
margin: 0 -2px;
}
12 changes: 6 additions & 6 deletions package/src/extensions/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PrismEditor } from "../../types"

const template = createTemplate(
"",
"color:#0000;display:none;contain:strict;padding:0 var(--padding-inline,.75em) 0 var(--padding-left);",
"color:#0000;display:none;contain:strict;padding:0 var(--_pse) 0 var(--padding-left);",
)

export type SearchFilter = (start: number, end: number) => boolean
Expand Down Expand Up @@ -64,7 +64,7 @@ const createSearchAPI = (editor: PrismEditor): SearchAPI => {
if (!useRegExp) str = regexEscape(str)
const value = editor.value,
searchStr = selection ? value.slice(...selection) : value,
offset = selection?.[0] || 0,
offset = selection ? selection[0] : 0,
flags = `gum${caseSensitive ? "" : "i"}`,
filterFn =
typeof filter == "number"
Expand All @@ -85,10 +85,10 @@ const createSearchAPI = (editor: PrismEditor): SearchAPI => {
flags,
)
while ((match = regex.exec(searchStr))) {
;(l = match[0].length) || regex.lastIndex++
index = match.index
if (!filterFn || filterFn(index, index + l))
matchPositions[i++] = [index + offset, index + l + offset]
l = match[0].length
index = match.index + offset
if (!l) regex.lastIndex += value.codePointAt(index)! > 0xffff ? 2 : 1
if (!filterFn || filterFn(index, index + l)) matchPositions[i++] = [index, index + l]
}
} catch (e) {
return (<Error>e).message
Expand Down

0 comments on commit 5fa8c2c

Please sign in to comment.