A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
editor: insert image/attachment after selected node
Abdullah Atta8d285c93d9b8
diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.tsindex dca9028e2..953810ef8 100644--- a/packages/editor/src/extensions/attachment/attachment.ts+++ b/packages/editor/src/extensions/attachment/attachment.ts@@ -121,7 +121,18 @@ export const AttachmentNode = Node.create<AttachmentOptions>({return {insertAttachment:(attachment) =>- ({ commands }) => {+ ({ commands, state }) => {+ const { $from } = state.selection;+ const maybeAttachmentNode = state.doc.nodeAt($from.pos);+ if (maybeAttachmentNode?.type === this.type) {+ return commands.insertContentAt(+ $from.pos + maybeAttachmentNode.nodeSize,+ {+ type: this.name,+ attrs: attachment+ }+ );+ }return commands.insertContent({type: this.name,attrs: attachmentdiff --git a/packages/editor/src/extensions/image/image.ts b/packages/editor/src/extensions/image/image.tsindex b2595b5fd..9cfc290fc 100644--- a/packages/editor/src/extensions/image/image.ts+++ b/packages/editor/src/extensions/image/image.ts@@ -209,8 +209,16 @@ export const ImageNode = Node.create<ImageOptions>({return {insertImage:(options) =>- ({ commands }) => {- console.log(options);+ ({ commands, state }) => {+ const { $from } = state.selection;+ const maybeImageNode = state.doc.nodeAt($from.pos);+ if (maybeImageNode?.type === this.type) {+ return commands.insertContentAt($from.pos + 1, {+ type: this.name,+ attrs: options+ });+ }+return commands.insertContent({type: this.name,attrs: options