Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions components/ai-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export function AIChat({
const followUpQuestionsRef = useRef<string[]>([]);
const followUpRequestIdRef = useRef(0);
const isComposingRef = useRef(false);
const compositionTimeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined);

useEffect(() => {
const viewport = scrollViewportRef.current;
Expand Down Expand Up @@ -1088,7 +1089,7 @@ export function AIChat({
}, [isLoading, sendMessage, followUpQuestions]);

const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter" && !e.shiftKey && !isComposingRef.current) {
if (e.key === "Enter" && !e.shiftKey && !isComposingRef.current && !e.nativeEvent.isComposing) {
e.preventDefault();
sendMessage();
}
Expand Down Expand Up @@ -1269,10 +1270,18 @@ export function AIChat({
onChange={(e) => setInput(e.target.value)}
onKeyDown={handleKeyDown}
onCompositionStart={() => {
clearTimeout(compositionTimeoutRef.current);
isComposingRef.current = true;
}}
onCompositionEnd={() => {
isComposingRef.current = false;
// Delay resetting the flag so the keydown handler for the
// same Enter keystroke still sees isComposing as true.
// In some browsers (e.g. Chrome with Chinese IME),
// compositionend fires before keydown for the Enter key
// that confirms the composition.
compositionTimeoutRef.current = setTimeout(() => {
isComposingRef.current = false;
}, 0);
Comment on lines 1276 to +1284
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onCompositionEnd schedules a setTimeout(0) that unconditionally sets isComposingRef.current = false. If a new composition starts before the timeout fires (e.g., user immediately continues composing), the pending timeout can incorrectly flip the flag to false while composition is active. Consider storing the timeout id (or a monotonically increasing composition sequence) in a ref and cancelling/invalidating it in onCompositionStart (and on unmount) before scheduling a new reset.

Copilot uses AI. Check for mistakes.
}}
placeholder="Ask about the video..."
className="resize-none rounded-[20px] text-xs bg-neutral-100 border-[#ebecee] pr-11"
Expand Down
2 changes: 1 addition & 1 deletion components/note-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function NoteEditor({ selectedText, metadata, currentTime, onSave }: Note
}, [originalQuote]);

const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
if (e.key === "Enter" && (e.metaKey || e.ctrlKey) && !e.nativeEvent.isComposing) {
e.preventDefault();
handleSave();
}
Expand Down
2 changes: 1 addition & 1 deletion components/transcript-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export function TranscriptViewer({
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') navigateSearch('next');
if (e.key === 'Enter' && !e.nativeEvent.isComposing) navigateSearch('next');
if (e.key === 'Escape') {
setIsSearchOpen(false);
setSearchQuery("");
Expand Down