fix(ai-toolbar): finalize normalized clipboard test coverage

This commit is contained in:
2026-04-23 10:38:35 -04:00
parent 251520fd29
commit 71e4133d57
4 changed files with 40 additions and 27 deletions

View File

@@ -95,10 +95,11 @@ function ShortcutsList({ os }: { os: Os }) {
function isEditableTarget(target: EventTarget | null): target is HTMLElement {
const element = target as HTMLElement | null;
return !!element && (
element.tagName === "TEXTAREA" ||
element.tagName === "INPUT" ||
element.isContentEditable
return (
!!element &&
(element.tagName === "TEXTAREA" ||
element.tagName === "INPUT" ||
element.isContentEditable)
);
}
@@ -187,8 +188,7 @@ export const AIToolbar = ({
// focused element or OS clipboard model (X11/Wayland).
// This is the approach used by Excalidraw's actionPaste.
useEffect(() => {
if (!(isAuthenticated && !isPending && canUseAi && !aiLoading))
return;
if (!(isAuthenticated && !isPending && canUseAi && !aiLoading)) return;
// ── Handler 1: paste event (works when textarea is NOT focused) ───────
const handleDocumentPaste = (e: ClipboardEvent) => {
@@ -281,7 +281,7 @@ export const AIToolbar = ({
document.removeEventListener("paste", handlePasteHandled, {
capture: true,
});
document.removeEventListener("keydown", handleDocumentKeydown);
document.removeEventListener("keydown", handleDocumentKeydown);
};
}, [isAuthenticated, isPending, canUseAi, aiLoading]); // onImagesSelect intentionally omitted — ref stays current