Skip to content

Commit 6920cc9

Browse files
committed
clean up empty search logic
1 parent bac2da9 commit 6920cc9

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

frontend/app/element/search.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ const SearchComponent = ({
4343
}, [isOpen]);
4444

4545
useEffect(() => {
46-
if (search) {
47-
setIndex(0);
48-
onSearch?.(search);
49-
}
46+
setIndex(0);
47+
setNumResults(0);
48+
onSearch?.(search);
5049
}, [search]);
5150

5251
const middleware: Middleware[] = [];

frontend/app/view/webview/webview.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ const WebView = memo(({ model, onFailLoad }: WebViewProps) => {
546546
const setNumSearchResults = useSetAtom(searchProps.numResultsAtom);
547547
const onSearch = useCallback((search: string) => {
548548
try {
549-
model.webviewRef.current?.findInPage(search);
549+
if (search) {
550+
model.webviewRef.current?.findInPage(search);
551+
} else {
552+
model.webviewRef.current?.stopFindInPage("clearSelection");
553+
}
550554
} catch (e) {
551555
console.error("Failed to search", e);
552556
}
@@ -574,15 +578,6 @@ const WebView = memo(({ model, onFailLoad }: WebViewProps) => {
574578
setNumSearchResults(result.matches);
575579
setSearchIndex(result.activeMatchOrdinal - 1);
576580
}, []);
577-
useEffect(() => {
578-
if (!isSearchOpen) {
579-
try {
580-
model.webviewRef.current?.stopFindInPage("clearSelection");
581-
} catch (e) {
582-
console.error("Failed to stop find in page", e);
583-
}
584-
}
585-
}, [isSearchOpen]);
586581
// End Search
587582

588583
// The initial value of the block metadata URL when the component first renders. Used to set the starting src value for the webview.

0 commit comments

Comments
 (0)