test(ai-toolbar): verify paste listener gating at component boundary

This commit is contained in:
2026-04-22 23:15:29 -04:00
parent 9f23597e53
commit 8cc868c22a
2 changed files with 130 additions and 75 deletions

View File

@@ -94,22 +94,6 @@ interface AIToolbarProps {
events: CalendarEvent[];
}
interface GlobalPasteCaptureGate {
isAuthenticated: boolean;
isPending: boolean;
canUseAi: boolean;
aiLoading: boolean;
}
export function shouldEnableGlobalPasteCapture({
isAuthenticated,
isPending,
canUseAi,
aiLoading,
}: GlobalPasteCaptureGate): boolean {
return isAuthenticated && !isPending && canUseAi && !aiLoading;
}
// ─── Component ────────────────────────────────────────────────────────────────
export const AIToolbar = ({
@@ -170,14 +154,7 @@ export const AIToolbar = ({
// focused element or OS clipboard model (X11/Wayland).
// This is the approach used by Excalidraw's actionPaste.
useEffect(() => {
if (
!shouldEnableGlobalPasteCapture({
isAuthenticated,
isPending,
canUseAi,
aiLoading,
})
)
if (!(isAuthenticated && !isPending && canUseAi && !aiLoading))
return;
// ── Handler 1: paste event (works when textarea is NOT focused) ───────