mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
fix scroll and wanakana
This commit is contained in:
1 parent
8e47278d2a
commit
41e207afad
1 file changed
+34
-7
@@ -43,6 +43,8 @@ function SearchPage() {
|
|||||||
|
|
||||||
const nSearch = useRef(0);
|
const nSearch = useRef(0);
|
||||||
const searchboxRef = useRef<HTMLInputElement | null>(null);
|
const searchboxRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
const resultScrollRef = useRef<HTMLElement | null>(null);
|
||||||
|
const prevNormQ = useRef("");
|
||||||
|
|
||||||
const lang = "ja-JP";
|
const lang = "ja-JP";
|
||||||
|
|
||||||
@@ -101,6 +103,8 @@ function SearchPage() {
|
|||||||
norm_q = norm_q.replace(/n$/i, "ん").replace(/[a-z]$/i, "");
|
norm_q = norm_q.replace(/n$/i, "ん").replace(/[a-z]$/i, "");
|
||||||
}
|
}
|
||||||
if (!norm_q) return;
|
if (!norm_q) return;
|
||||||
|
if (isNew && prevNormQ.current === norm_q) return;
|
||||||
|
prevNormQ.current = norm_q;
|
||||||
|
|
||||||
const ender = /\p{Z}$/u.test(q) ? "" : "*";
|
const ender = /\p{Z}$/u.test(q) ? "" : "*";
|
||||||
|
|
||||||
@@ -150,6 +154,10 @@ function SearchPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resultScrollRef.current) {
|
||||||
|
resultScrollRef.current.scrollTop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
setEntries(result);
|
setEntries(result);
|
||||||
} else {
|
} else {
|
||||||
setEntries([...entries, ...result]);
|
setEntries([...entries, ...result]);
|
||||||
@@ -178,11 +186,13 @@ function SearchPage() {
|
|||||||
|
|
||||||
function onSearchboxChange(q: string) {
|
function onSearchboxChange(q: string) {
|
||||||
if (isAutoKana) {
|
if (isAutoKana) {
|
||||||
q = toKana(
|
q = toKana(q, {
|
||||||
q,
|
useObsoleteKana: true,
|
||||||
{ useObsoleteKana: true, IMEMode: true },
|
IMEMode: true,
|
||||||
Object.fromEntries("<>[]".split("").map((c) => [c, c])),
|
customKanaMapping: Object.fromEntries(
|
||||||
);
|
"<>[]".split("").map((c) => [c, c]),
|
||||||
|
),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setQ(q);
|
setQ(q);
|
||||||
@@ -199,7 +209,10 @@ function SearchPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const addFurigana: CompositionEventHandler = ({ data: compositionData }) => {
|
const addFurigana: CompositionEventHandler = ({
|
||||||
|
data: compositionData,
|
||||||
|
target,
|
||||||
|
}) => {
|
||||||
const cleanedFuri = [...furigana.replace(/n/g, "ん")]
|
const cleanedFuri = [...furigana.replace(/n/g, "ん")]
|
||||||
.map((c) => katakanaToHiragana(c))
|
.map((c) => katakanaToHiragana(c))
|
||||||
.join("");
|
.join("");
|
||||||
@@ -223,7 +236,20 @@ function SearchPage() {
|
|||||||
const markup = parts
|
const markup = parts
|
||||||
.map((p, idx) => (idx & 1 ? `<${p}>[${rt[idx]}]` : p))
|
.map((p, idx) => (idx & 1 ? `<${p}>[${rt[idx]}]` : p))
|
||||||
.join("");
|
.join("");
|
||||||
setQ(markup);
|
|
||||||
|
setQ((q) => {
|
||||||
|
if (!(target instanceof HTMLInputElement)) return markup;
|
||||||
|
|
||||||
|
let { selectionStart } = target;
|
||||||
|
selectionStart = selectionStart || 0;
|
||||||
|
if (selectionStart < compositionData.length) return markup;
|
||||||
|
|
||||||
|
return (
|
||||||
|
q.substring(0, selectionStart - compositionData.length) +
|
||||||
|
markup +
|
||||||
|
q.substring(selectionStart)
|
||||||
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function katakanaToHiragana(k: string) {
|
function katakanaToHiragana(k: string) {
|
||||||
@@ -298,6 +324,7 @@ function SearchPage() {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<Box
|
<Box
|
||||||
|
ref={resultScrollRef}
|
||||||
as={"ol"}
|
as={"ol"}
|
||||||
listStyleType={"number"}
|
listStyleType={"number"}
|
||||||
style={{ overflowY: "scroll", scrollbarWidth: "none" }}
|
style={{ overflowY: "scroll", scrollbarWidth: "none" }}
|
||||||
|
|||||||
Reference in new issue
Block a user