Skip to content

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

feat: add support for pasting attachments into editor

thecodrra83b831628a3
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 3d402e744..b50303659 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -68,6 +68,7 @@ export default function EditorManager({
const title = useRef<string>("");
const previewSession = useRef<PreviewSession>();
const [dropRef, overlayRef] = useDragOverlay();
+ const editor = useEditorInstance();
const arePropertiesVisible = useStore((store) => store.arePropertiesVisible);
const toggleProperties = useStore((store) => store.toggleProperties);
@@ -128,6 +129,21 @@ export default function EditorManager({
alignSelf: "stretch",
overflow: "hidden",
}}
+ onPaste={async (event) => {
+ if (!editor) return;
+
+ if (event.clipboardData?.items?.length) {
+ event.preventDefault();
+
+ for (let item of event.clipboardData.items) {
+ const file = item.getAsFile();
+ if (!file) continue;
+ const result = await attachFile(file);
+ if (!result) continue;
+ editor.attachFile(result);
+ }
+ }
+ }}
>
{previewSession.current && (
<PreviewModeNotice