mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 11:47:54 +01:00
editor: insert image/attachment after selected node
This commit is contained in:
committed by
Abdullah Atta
parent
fc10e957fb
commit
8d285c93d9
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user