fix(ai-toolbar): tighten modifier and clipboard fallback guards
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user