fix(ui): guard the remaining comment inputs against IME composition
The IME fix covered the diff/file comment input and the browser annotation overlay, but two other places where a user writes a comment still acted on the Enter that confirms an IME candidate: the chat quote comment in the text selection menu, and the in-place comment editor on a composer context chip. Confirming a candidate there attached or committed the half-typed reading and closed the input. Escape, which abandons a candidate, had the same problem. Both handlers now return early on a composing keystroke, and a single test asserts the guard across every comment input so the next one added does not quietly skip it.
This commit is contained in:
@@ -14,6 +14,7 @@ import React from 'react';
|
||||
import { Icon } from '@/components/icon/Icon';
|
||||
import type { IconName } from '@/components/icon/icons';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { isIMECompositionEvent } from '@/lib/ime';
|
||||
import { getRuntimeKey } from '@/lib/runtime-switch';
|
||||
import {
|
||||
EMPTY_INLINE_COMMENT_DRAFTS,
|
||||
@@ -165,6 +166,10 @@ const DraftPreviewEntry: React.FC<{
|
||||
onChange={(event) => setEditText(event.target.value)}
|
||||
onBlur={commitEdit}
|
||||
onKeyDown={(event) => {
|
||||
// An IME candidate is confirmed with Enter and
|
||||
// abandoned with Escape; neither keystroke should
|
||||
// commit or revert the edit.
|
||||
if (isIMECompositionEvent(event)) return;
|
||||
if (event.key === 'Enter' && !event.shiftKey) {
|
||||
event.preventDefault();
|
||||
commitEdit();
|
||||
|
||||
@@ -16,6 +16,7 @@ import { resolveProjectForSessionDirectory } from '@/lib/projectResolution';
|
||||
import { useEffectiveDirectory } from '@/hooks/useEffectiveDirectory';
|
||||
import { isVSCodeRuntime } from '@/lib/desktop';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { isIMECompositionEvent } from '@/lib/ime';
|
||||
import { rangeToMarkdown, trimSelectionValue, wrapMarkdownSelectionForChat } from './selectionMarkdown';
|
||||
import { focusChatInput } from '@/components/chat/composer/editor/dom';
|
||||
import { registerActiveSelectionToolbar } from '@/lib/addSelectionToChat';
|
||||
@@ -590,6 +591,9 @@ export const TextSelectionMenu: React.FC<TextSelectionMenuProps> = ({ containerR
|
||||
resizeCommentInput();
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
// An IME candidate is confirmed with Enter and abandoned with
|
||||
// Escape; neither keystroke belongs to the comment yet.
|
||||
if (isIMECompositionEvent(event)) return;
|
||||
// Desktop: Enter attaches, Shift+Enter breaks the line. Mobile
|
||||
// keyboards use Enter for line breaks; attaching is the button's job.
|
||||
if (event.key === 'Enter' && !event.shiftKey && !isMobile) {
|
||||
|
||||
Reference in New Issue
Block a user