Search the whole document in Find, and stop negative charcode caches sticking

This commit is contained in:
Anthony Stirling
2026-08-25 09:36:58 +01:00
parent 7d2abdccef
commit df696f440c
3 changed files with 19 additions and 4 deletions
@@ -240,10 +240,12 @@ function maybeAutoPrefetch(
}
// Stop the per-keystroke prefetch storm. resolve looks these
// chars up under the QUERIED font, not perCharFont.
// chars up under the QUERIED font, not perCharFont. Use the
// TTL'd null: this font was never actually asked, so a permanent
// null would kill the pair for the rest of the session.
if (perCharFont !== fontPtr) {
for (const ch of fontChars) {
charCache.set(cacheKey(fontPtr, ch), null);
setTransientNull(cacheKey(fontPtr, ch));
}
}
}
@@ -140,8 +140,12 @@ export function charcodesResolveFully(
} catch {
ok = false;
}
perFont.set(ch, ok);
if (!ok) return false;
// Only memoise a POSITIVE result. A miss here can simply mean the
// charcode cache was cold or the backend was briefly unreachable, and
// caching that as "this font cannot encode this character" made the
// failure permanent for the session.
if (ok) perFont.set(ch, true);
else return false;
}
return true;
}
@@ -13,6 +13,7 @@ import type {
MatchOptions,
TextMatch,
} from "@app/tools/pdfTextEditor/v2/util/textMatching";
import { ensureAllPagesRead } from "@app/tools/pdfTextEditor/v2/hooks/useDocumentLoader";
import type { EditorStore } from "@app/tools/pdfTextEditor/v2/store/EditorStore";
import type {
PageSnapshot,
@@ -60,6 +61,14 @@ export function FindBar({ store, pages, onClose }: FindBarProps) {
inputRef.current?.focus();
}, []);
// Opening Find is a document-wide request, so pull in every page that lazy
// loading has not read yet. Yield first: the read is synchronous, and on a
// long document it would otherwise block before the bar has painted.
useEffect(() => {
const id = setTimeout(() => ensureAllPagesRead(store), 0);
return () => clearTimeout(id);
}, [store]);
const options: MatchOptions = useMemo(
() => ({ matchCase, wholeWord, ignoreAccents }),
[matchCase, wholeWord, ignoreAccents],