editor: insert image/attachment after selected node

This commit is contained in:
Abdullah Atta
2023-06-23 14:21:52 +05:00
committed by Abdullah Atta
parent fc10e957fb
commit 8d285c93d9
2 changed files with 22 additions and 3 deletions

View File

@@ -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: attachment

View File

@@ -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