fix(ai-toolbar): tighten modifier and clipboard fallback guards

This commit is contained in:
2026-04-23 04:47:11 -04:00
parent 470d76d46c
commit d9aa035dce
2 changed files with 65 additions and 3 deletions

View File

@@ -40,6 +40,15 @@ function useOs(): Os {
return os;
}
function createClipboardFallbackFile(blob: Blob, index: number): File {
const createdAt = Date.now() + index;
const extension = blob.type.split("/")[1] || "png";
return new File([blob], `clipboard-image-${createdAt}.${extension}`, {
type: blob.type,
lastModified: createdAt,
});
}
// ─── Shared shortcuts list (rendered in both HoverCard and Popover) ───────────
function ShortcutsList({ os }: { os: Os }) {
@@ -220,9 +229,7 @@ export const AIToolbar = ({
for (const mimeType of typesToTry) {
try {
const blob = await clipboardItem.getType(mimeType);
files.push(
new File([blob], "clipboard-image", { type: mimeType }),
);
files.push(createClipboardFallbackFile(blob, files.length));
break; // got this item, move to next clipboardItem
} catch {
// NotFoundError — type not present, try next
@@ -310,6 +317,8 @@ export const AIToolbar = ({
if (
e.key === "Enter" &&
(e.metaKey || e.ctrlKey) &&
!e.shiftKey &&
!e.altKey &&
!aiLoading &&
canUseAi &&
(aiPrompt.trim() || hasImages)