From 6a8318c2e441e2c2339556c573ebe2181de480b9 Mon Sep 17 00:00:00 2001 From: blue Date: Mon, 16 Feb 2026 16:07:43 +0900 Subject: [PATCH] fix(ui): prevent annotation toolbar from stealing global comment focus --- packages/ui/components/AnnotationToolbar.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/ui/components/AnnotationToolbar.tsx b/packages/ui/components/AnnotationToolbar.tsx index 5e40659..ed7965e 100644 --- a/packages/ui/components/AnnotationToolbar.tsx +++ b/packages/ui/components/AnnotationToolbar.tsx @@ -5,6 +5,13 @@ import { AttachmentsButton } from "./AttachmentsButton"; type PositionMode = 'center-above' | 'top-right'; +const isEditableElement = (node: EventTarget | Element | null): boolean => { + if (!(node instanceof Element)) return false; + if (node.matches('input, textarea, select, [role="textbox"]')) return true; + if (node.closest('[contenteditable]:not([contenteditable="false"])')) return true; + return (node as HTMLElement).isContentEditable; +}; + interface AnnotationToolbarProps { element: HTMLElement; positionMode: PositionMode; @@ -129,6 +136,9 @@ export const AnnotationToolbar: React.FC = ({ if (step !== "menu") return; const handleKeyDown = (e: KeyboardEvent) => { + // Protect global comment and any editable field focus from type-to-comment capture. + if (e.isComposing) return; + if (isEditableElement(e.target) || isEditableElement(document.activeElement)) return; // Escape closes the toolbar if (e.key === "Escape") { onClose(); return; } // Ignore if modifier keys are held (except shift for capitals) @@ -146,7 +156,7 @@ export const AnnotationToolbar: React.FC = ({ window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); - }, [step]); + }, [step, onClose]); if (!position) return null;