Skip to content

Commit de97b89

Browse files
Improve search result highlighting
1 parent 6ddb917 commit de97b89

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

src/app/globals.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,13 @@
7676
.cm-editor .cm-lineNumbers .cm-gutterElement {
7777
padding-left: 0.5;
7878
text-align: left;
79+
}
80+
81+
.cm-editor .cm-searchMatch {
82+
border: dotted;
83+
background: transparent;
84+
}
85+
86+
.cm-editor .cm-searchMatch-selected {
87+
border: solid;
7988
}

src/app/search/components/searchResultsPanel/codePreview.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ import CodeMirror, { Decoration, DecorationSet, EditorState, EditorView, ReactCo
99
import { useMemo, useRef } from "react";
1010

1111
const markDecoration = Decoration.mark({
12-
class: "cm-searchMatch"
13-
});
14-
15-
const cmTheme = EditorView.baseTheme({
16-
"&light .cm-searchMatch": {
17-
border: "1px #6b7280ff",
18-
},
19-
"&dark .cm-searchMatch": {
20-
border: "1px #d1d5dbff",
21-
},
12+
class: "cm-searchMatch-selected"
2213
});
2314

2415
interface CodePreviewProps {
@@ -79,7 +70,6 @@ export const CodePreview = ({
7970
},
8071
provide: (field) => EditorView.decorations.from(field),
8172
}),
82-
cmTheme
8373
];
8474
}, [ranges, lineOffset]);
8575

src/lib/extensions/searchResultHighlightExtension.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,10 @@ const matchHighlighter = StateField.define<DecorationSet>({
4646
});
4747

4848
const matchMark = Decoration.mark({
49-
class: "tq-searchMatch"
49+
class: "cm-searchMatch"
5050
});
5151
const selectedMatchMark = Decoration.mark({
52-
class: "tq-searchMatch-selected"
53-
});
54-
55-
const highlightTheme = EditorView.baseTheme({
56-
"&light .tq-searchMatch": {
57-
border: "1px dotted #6b7280ff",
58-
},
59-
"&light .tq-searchMatch-selected": {
60-
backgroundColor: "#00ff00aa"
61-
},
62-
63-
"&dark .tq-searchMatch": {
64-
border: "1px dotted #d1d5dbff",
65-
},
66-
"&dark .tq-searchMatch-selected": {
67-
backgroundColor: "#00ff007a",
68-
}
52+
class: "cm-searchMatch-selected"
6953
});
7054

7155
export const highlightRanges = (selectedMatchIndex: number, ranges: SearchResultRange[], view: EditorView) => {
@@ -90,7 +74,6 @@ export const highlightRanges = (selectedMatchIndex: number, ranges: SearchResult
9074

9175
export const searchResultHighlightExtension = (): Extension => {
9276
return [
93-
highlightTheme,
9477
matchHighlighter,
9578
]
9679
}

0 commit comments

Comments
 (0)