word segmentation and clipboard first word detector

This commit is contained in:
polv committed 2026-03-06 02:25:49 +07:00
1 parent 29a4d14893
commit 1614db6e99
19 files changed
+502 -13

No files matched your search

+19 -1
View File
@@ -94,7 +94,9 @@ function SearchPage() {
}
async function runSearch(isNew = true) {
let norm_q = q.trim();
let norm_q = q.split(" ")[0].trim();
const isFromSplit = norm_q !== q.trim();
if (isAutoKana) {
norm_q = norm_q.replace(/n$/i, "ん").replace(/[a-z]$/i, "");
}
@@ -132,6 +134,22 @@ function SearchPage() {
});
if (isNew) {
if (!result.length && !isFromSplit && ender === "" && q.length > 2) {
const segs = await invoke<{ surface: string }[]>("tokenize", {
text: q,
});
if (segs.length > 1) {
const newQ =
segs.shift()!.surface +
" " +
segs.map((s) => s.surface).join("") +
" ";
setQ(newQ);
return;
}
}
setEntries(result);
} else {
setEntries([...entries, ...result]);