mirror of
https://github.com/docmost/docmost.git
synced 2026-09-01 03:15:32 +08:00
use search key check
This commit is contained in:
@@ -417,25 +417,31 @@ function CollabPageEditor({
|
|||||||
const hasConnectedOnceRef = useRef(false);
|
const hasConnectedOnceRef = useRef(false);
|
||||||
const [showStatic, setShowStatic] = useState(true);
|
const [showStatic, setShowStatic] = useState(true);
|
||||||
|
|
||||||
const appliedSearchRef = useRef(false);
|
const appliedSearchKeyRef = useRef<string | null>(null);
|
||||||
const searchQueries = searchParams.getAll("q");
|
const searchKey = `${pageId}:${searchParams.toString()}`;
|
||||||
const match = searchParams.get("m");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!editor || editor.isDestroyed) return;
|
if (
|
||||||
if (showStatic || !isSynced) return;
|
!editor ||
|
||||||
if (!searchQueries.length || appliedSearchRef.current) return;
|
editor.isDestroyed ||
|
||||||
if (!editor || editor.isDestroyed || !editor.view.dom.isConnected) return;
|
!editor.view.dom.isConnected ||
|
||||||
|
appliedSearchKeyRef.current === searchKey
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
appliedSearchRef.current = true;
|
const searchQueries = searchParams.getAll("q");
|
||||||
|
const match = searchParams.get("m");
|
||||||
|
if (!searchQueries.length) return;
|
||||||
|
|
||||||
|
appliedSearchKeyRef.current = searchKey;
|
||||||
|
|
||||||
document.dispatchEvent(
|
document.dispatchEvent(
|
||||||
new CustomEvent("openSearchNavigationDialog", {
|
new CustomEvent("openSearchNavigationDialog", {
|
||||||
detail: { searchTerms: searchQueries, wholeWord: match === "whole" },
|
detail: { searchTerms: searchQueries, wholeWord: match === "whole" },
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}, [editor, isSynced, showStatic, searchKey, searchParams]);
|
||||||
}, [editor, isSynced, showStatic, searchQueries]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user