Files
DeepTutor/web/lib/use-ime-composing.ts
Bingxi Zhao (Frank) b030697df7 refactor(web): shared IME-composing hook + citation-anchor helper; symmetric scrollbar gutter
Follow-up to #615/#608/#634: the isComposingRef + composition-handler
trio duplicated across five textareas (ComposerInput,
SimpleComposerInput, ChatMessages edit, BookChatPanel, PartnerComposer)
becomes one useImeComposing() hook; the citation-anchor fallback chain
+ <details> auto-open duplicated in both markdown renderers moves to
lib/markdown-anchors.ts; and the chat scrollport reserves the
scrollbar gutter on both edges so the message column centers on the
same axis as header and composer on classic-scrollbar platforms.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 01:38:06 +08:00

29 lines
996 B
TypeScript

/**
* Shared IME composition guard for chat textareas. While the user is
* composing (e.g. picking CJK candidates), Enter confirms a candidate
* rather than submitting — keydown handlers read ``isComposingRef.current``
* (typically via ``shouldSubmitOnEnter``) to tell the two apart. Sharing
* one hook keeps the deferred reset below from being "simplified" away
* at individual call sites, which would break CJK input.
*/
import { useCallback, useRef } from "react";
export function useImeComposing() {
const isComposingRef = useRef(false);
const onCompositionStart = useCallback(() => {
isComposingRef.current = true;
}, []);
const onCompositionEnd = useCallback(() => {
// Some IMEs fire compositionend before the Enter keydown that confirms
// a candidate, so keep the guard through the current event turn.
setTimeout(() => {
isComposingRef.current = false;
}, 0);
}, []);
return { isComposingRef, onCompositionStart, onCompositionEnd };
}