Skip to content

Commit 4f52494

Browse files
(fix) Fix issue with match highlighting not appearing when first clicking on a search result. Fixes #255
1 parent e57a981 commit 4f52494

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [3.0.1] - 2025-04-01
11+
12+
### Fixes
13+
- Fix issue with match highlighting not appearing when first clicking on a search result. ([#255](https://github.com/sourcebot-dev/sourcebot/issues/255))
14+
1015
## [3.0.0] - 2025-04-01
1116

1217
Sourcebot v3 is here and brings a number of structural changes to the tool's foundation, including a SQL database, parallelized indexing, authentication support, multitenancy, and more. Checkout the [migration guide](https://docs.sourcebot.dev/self-hosting/upgrade/v2-to-v3-guide) for information on upgrading your instance to v3.

packages/web/src/app/[domain]/search/components/codePreviewPanel/codePreview.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Scrollbar } from "@radix-ui/react-scroll-area";
1616
import CodeMirror, { ReactCodeMirrorRef, SelectionRange } from '@uiw/react-codemirror';
1717
import clsx from "clsx";
1818
import { ArrowDown, ArrowUp } from "lucide-react";
19-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
19+
import { useCallback, useEffect, useMemo, useState } from "react";
2020

2121
export interface CodePreviewFile {
2222
content: string;
@@ -42,13 +42,13 @@ export const CodePreview = ({
4242
onSelectedMatchIndexChange,
4343
onClose,
4444
}: CodePreviewProps) => {
45-
const editorRef = useRef<ReactCodeMirrorRef>(null);
45+
const [editorRef, setEditorRef] = useState<ReactCodeMirrorRef | null>(null);
4646

4747
const [gutterWidth, setGutterWidth] = useState(0);
4848
const theme = useCodeMirrorTheme();
4949

50-
const keymapExtension = useKeymapExtension(editorRef.current?.view);
51-
const syntaxHighlighting = useSyntaxHighlightingExtension(file?.language ?? '', editorRef.current?.view);
50+
const keymapExtension = useKeymapExtension(editorRef?.view);
51+
const syntaxHighlighting = useSyntaxHighlightingExtension(file?.language ?? '', editorRef?.view);
5252
const [currentSelection, setCurrentSelection] = useState<SelectionRange>();
5353

5454
const extensions = useMemo(() => {
@@ -89,12 +89,12 @@ export const CodePreview = ({
8989
}, [file]);
9090

9191
useEffect(() => {
92-
if (!file || !editorRef.current?.view) {
92+
if (!file || !editorRef?.view) {
9393
return;
9494
}
9595

96-
highlightRanges(selectedMatchIndex, ranges, editorRef.current.view);
97-
}, [ranges, selectedMatchIndex, file]);
96+
highlightRanges(selectedMatchIndex, ranges, editorRef.view);
97+
}, [ranges, selectedMatchIndex, file, editorRef]);
9898

9999
const onUpClicked = useCallback(() => {
100100
onSelectedMatchIndexChange(selectedMatchIndex - 1);
@@ -174,21 +174,21 @@ export const CodePreview = ({
174174
</div>
175175
<ScrollArea className="h-full overflow-auto flex-1">
176176
<CodeMirror
177-
ref={editorRef}
177+
ref={setEditorRef}
178178
className="relative"
179179
readOnly={true}
180180
value={file?.content}
181181
extensions={extensions}
182182
theme={theme}
183183
>
184184
{
185-
editorRef.current?.view &&
185+
editorRef?.view &&
186186
file?.filepath &&
187187
repoName &&
188188
currentSelection &&
189189
(
190190
<EditorContextMenu
191-
view={editorRef.current.view}
191+
view={editorRef.view}
192192
path={file?.filepath}
193193
repoName={repoName}
194194
selection={currentSelection}

0 commit comments

Comments
 (0)