import { useRef } from "react"; import type { RefObject } from "react"; import { Button } from "@/components/ui/button.js"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog.js"; import { Input } from "@/components/ui/input.js"; import { isImeComposingKeyEvent } from "@/lib/imeComposition.js"; import { logger } from "@/logger.js"; export function TaskRenameDialog({ open, value, inputRef, intl, /** 覆盖标题/占位文案;缺省回退任务重命名文案(workspace 别名等复用同一对话框)。 */ title = intl.formatMessage({ id: "taskList.rename" }), placeholder = intl.formatMessage({ id: "taskList.renamePlaceholder" }), onOpenChange, onChange, onCancel, onConfirm, }: { open: boolean; value: string; inputRef: RefObject; intl: { formatMessage: (desc: { id: string }, values?: Record) => string; }; title?: string; placeholder?: string; onOpenChange: (open: boolean) => void; onChange: (value: string) => void; onCancel: () => void; onConfirm: () => void; }) { const compositionActiveRef = useRef(false); return (
{title}
{ onChange(event.target.value); }} onCompositionEnd={() => { compositionActiveRef.current = false; }} onCompositionStart={() => { compositionActiveRef.current = true; }} onKeyDown={(event) => { if (event.key === "Enter") { if ( isImeComposingKeyEvent({ compositionActive: compositionActiveRef.current, nativeEvent: event.nativeEvent, }) ) { // task 重命名里中文输入法 Enter 是候选确认,不是确认按钮。 // 同时读取本地 composition 状态,避免平台事件时序让 isComposing 提前变 false。 logger.debug("[TaskRenameDialog] ignore rename enter during IME", { valueLength: value.length, }); return; } event.preventDefault(); logger.info("[TaskRenameDialog] rename confirm via enter", { valueLength: value.length, trimmedLength: value.trim().length, }); onConfirm(); } }} />
); }