mirror of
https://github.com/docmost/docmost.git
synced 2026-09-11 07:56:54 +08:00
feat: jump to search (#2453)
* jump to search init * support multiple text matching * search navigation dialog * remove search text * typesense support * typesense support * add search guard * use search key check * minor fix * minor fix * fix: clean up jump search state on close --------- Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import type { useEditor } from "@tiptap/react";
|
||||
|
||||
interface UseSearchNavigationParamsProps {
|
||||
editor: ReturnType<typeof useEditor>;
|
||||
isSynced: boolean;
|
||||
pageId: string;
|
||||
searchParams: URLSearchParams;
|
||||
showStatic: boolean;
|
||||
}
|
||||
|
||||
export function useSearchNavigationParams({
|
||||
editor,
|
||||
isSynced,
|
||||
pageId,
|
||||
searchParams,
|
||||
showStatic,
|
||||
}: UseSearchNavigationParamsProps) {
|
||||
const appliedSearchKeyRef = useRef<string | null>(null);
|
||||
const searchKey = `${pageId}:${searchParams.toString()}`;
|
||||
|
||||
useEffect(() => {
|
||||
const searchQueries = searchParams.getAll("q");
|
||||
if (!searchQueries.length) {
|
||||
appliedSearchKeyRef.current = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!editor ||
|
||||
editor.isDestroyed ||
|
||||
!editor.view.dom.isConnected ||
|
||||
appliedSearchKeyRef.current === searchKey
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const match = searchParams.get("m");
|
||||
appliedSearchKeyRef.current = searchKey;
|
||||
|
||||
document.dispatchEvent(
|
||||
new CustomEvent("openSearchNavigationDialog", {
|
||||
detail: { searchTerms: searchQueries, wholeWord: match === "whole" },
|
||||
}),
|
||||
);
|
||||
}, [editor, isSynced, searchKey, searchParams, showStatic]);
|
||||
}
|
||||
Reference in New Issue
Block a user