Skip to content

Commit 442a37d

Browse files
committed
feat: copy的时候支持图片
1 parent 69b1410 commit 442a37d

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

apps/web/src/components/memo-editor-form.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,7 @@ export const MemoEditorForm = view(
607607
});
608608
};
609609

610-
const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
611-
const files = Array.from(e.target.files || []);
610+
const uploadFiles = async (files: File[]) => {
612611
if (files.length === 0) return;
613612

614613
// 检查数量限制
@@ -665,13 +664,32 @@ export const MemoEditorForm = view(
665664
});
666665
}
667666
}
667+
};
668668

669+
const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
670+
const files = Array.from(e.target.files || []);
671+
await uploadFiles(files);
669672
// 重置 input
670673
if (fileInputRef.current) {
671674
fileInputRef.current.value = '';
672675
}
673676
};
674677

678+
const handlePaste = async (e: React.ClipboardEvent<HTMLTextAreaElement>) => {
679+
const imageFiles = Array.from(e.clipboardData.items)
680+
.filter((item) => item.type.startsWith('image/'))
681+
.map((item) => item.getAsFile())
682+
.filter((file): file is File => file !== null);
683+
684+
if (imageFiles.length === 0) return;
685+
686+
e.preventDefault();
687+
if (!isEditorActive) {
688+
setIsEditorActive(true);
689+
}
690+
await uploadFiles(imageFiles);
691+
};
692+
675693
// OCR 专用文件选择处理函数 - 先上传附件,再调用 OCR 服务
676694
const handleOCRFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
677695
const files = Array.from(e.target.files || []);
@@ -945,6 +963,7 @@ export const MemoEditorForm = view(
945963
onFocus={handleFocus}
946964
onBlur={handleBlur}
947965
onKeyDown={handleKeyDown}
966+
onPaste={handlePaste}
948967
placeholder={mode === 'create' ? '记录你的想法... (⌘+Enter)' : '编辑你的笔记...'}
949968
className="w-full px-0 py-0 bg-transparent text-gray-900 dark:text-gray-50 rounded-lg focus:outline-none resize-none placeholder-gray-400 dark:placeholder-gray-600 text-sm leading-relaxed"
950969
style={{ minHeight: '120px', maxHeight: '480px' }}

0 commit comments

Comments
 (0)