Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: support drag & drop images on iOS

Ammar Ahmed068ee8dc6806
diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsx
index 2a4192880..1337842e0 100644
--- a/packages/editor-mobile/src/components/editor.tsx
+++ b/packages/editor-mobile/src/components/editor.tsx
@@ -95,6 +95,7 @@ const Tiptap = ({
transaction.getMeta("ignoreEdit")
);
},
+
openAttachmentPicker: (type) => {
globalThis.editorControllers[tab.id]?.openFilePicker(type);
return true;
@@ -132,7 +133,39 @@ const Tiptap = ({
element: getContentDiv(),
editable: !tab.readonly,
editorProps: {
- editable: () => !tab.readonly
+ editable: () => !tab.readonly,
+ handlePaste: (view, event) => {
+ const hasFiles = event.clipboardData?.types?.some((type) =>
+ type.startsWith("Files")
+ );
+ if (hasFiles && event.clipboardData?.files?.length) {
+ let stopped = false;
+ for (let i = 0; i < event.clipboardData.files.length; i++) {
+ const file = event.clipboardData.files.item(i);
+ if (!file) continue;
+ if (!stopped) {
+ event.preventDefault();
+ event.stopPropagation();
+ stopped = true;
+ }
+ if (!file?.type.startsWith("image/")) continue;
+ const reader = new FileReader();
+ reader.onload = () => {
+ const data = reader.result;
+ if (typeof data === "string") {
+ editors[tabRef.current.id]?.commands.insertImage({
+ src: data,
+ filename: file.name,
+ mime: file.type,
+ size: file.size
+ });
+ }
+ };
+ reader.readAsDataURL(file);
+ }
+ return true;
+ }
+ }
},
content: globalThis.editorControllers[tab.id]?.content?.current,
isMobile: true,