fix(ai-toolbar): ignore editable targets during global paste fallback

This commit is contained in:
2026-04-22 23:19:18 -04:00
parent 8cc868c22a
commit 46f7aff815
2 changed files with 132 additions and 6 deletions

View File

@@ -69,6 +69,15 @@ 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
);
}
// ─── Types ────────────────────────────────────────────────────────────────────
interface AIToolbarProps {
@@ -159,12 +168,7 @@ export const AIToolbar = ({
// ── Handler 1: paste event (works when textarea is NOT focused) ───────
const handleDocumentPaste = (e: ClipboardEvent) => {
const target = e.target as HTMLElement;
const isEditableTarget =
target.tagName === "TEXTAREA" ||
target.tagName === "INPUT" ||
target.isContentEditable;
if (isEditableTarget) return; // textarea's own onPaste covers this
if (isEditableTarget(e.target)) return; // textarea's own onPaste covers this
const images = extractAllImagesFromClipboard(e.clipboardData ?? null);
if (images.length > 0) {
@@ -192,6 +196,7 @@ export const AIToolbar = ({
const isV = e.key === "v" || e.key === "V";
const isModifier = e.ctrlKey || e.metaKey;
if (!isV || !isModifier || e.shiftKey || e.altKey) return;
if (isEditableTarget(e.target)) return;
pasteHandledByEvent = false;