Add safety to range highlighting for search result panel

This commit is contained in:
bkellam 2024-09-17 23:58:29 -07:00
parent 1d8335b699
commit 649223a607

View file

@ -239,9 +239,26 @@ const CodePreview = ({
.sort((a, b) => { .sort((a, b) => {
return a.Start.ByteOffset - b.Start.ByteOffset; return a.Start.ByteOffset - b.Start.ByteOffset;
}) })
.filter(({ Start, End }) => {
const startLine = Start.LineNumber - lineOffset;
const endLine = End.LineNumber - lineOffset;
if (
startLine < 1 ||
endLine < 1 ||
startLine > document.lines ||
endLine > document.lines
) {
return false;
}
return true;
})
.map(({ Start, End }) => { .map(({ Start, End }) => {
const from = document.line(Start.LineNumber - lineOffset).from + Start.Column - 1; const startLine = Start.LineNumber - lineOffset;
const to = document.line(End.LineNumber - lineOffset).from + End.Column - 1; const endLine = End.LineNumber - lineOffset;
const from = document.line(startLine).from + Start.Column - 1;
const to = document.line(endLine).from + End.Column - 1;
return markDecoration.range(from, to); return markDecoration.range(from, to);
}); });
@ -254,7 +271,7 @@ const CodePreview = ({
}), }),
cmTheme cmTheme
]; ];
}, [ranges]); }, [ranges, lineOffset]);
const extensions = useMemo(() => { const extensions = useMemo(() => {
return [ return [