From 6b65af8fc31ffbbcf79b89bfdaceee7aadbf3f27 Mon Sep 17 00:00:00 2001 From: Dominik <6538827+bdbch@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:21:58 +0200 Subject: [PATCH] fix(core): fix cut and insertContentAt functions (#4187) --- packages/core/src/commands/cut.ts | 4 +++- packages/core/src/commands/insertContentAt.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/src/commands/cut.ts b/packages/core/src/commands/cut.ts index 2ee34fb676..e07247b643 100644 --- a/packages/core/src/commands/cut.ts +++ b/packages/core/src/commands/cut.ts @@ -19,7 +19,9 @@ export const cut: RawCommands['cut'] = (originRange, targetPos) => ({ editor }) return editor .chain() .deleteRange(originRange) - .insertContentAt(targetPos, contentSlice.content.toJSON()) + .command(({ commands, tr }) => { + return commands.insertContentAt(tr.mapping.map(targetPos), contentSlice.content.toJSON()) + }) .focus() .run() } diff --git a/packages/core/src/commands/insertContentAt.ts b/packages/core/src/commands/insertContentAt.ts index ba30035fc9..68589c5a22 100644 --- a/packages/core/src/commands/insertContentAt.ts +++ b/packages/core/src/commands/insertContentAt.ts @@ -46,7 +46,7 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value, return true } - let { from, to } = typeof position === 'number' ? { from: tr.mapping.map(position), to: tr.mapping.map(position) } : { from: tr.mapping.map(position.from), to: tr.mapping.map(position.to) } + let { from, to } = typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to } let isOnlyTextContent = true let isOnlyBlockContent = true