From daf14f17c7c206e12b59274d6b8f018cda2e6cef Mon Sep 17 00:00:00 2001 From: Palanikannan M Date: Mon, 28 Oct 2024 16:56:02 +0530 Subject: [PATCH] fix: table insertion --- .../editor/src/core/extensions/table/table/table.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/core/extensions/table/table/table.ts b/packages/editor/src/core/extensions/table/table/table.ts index 981788f548..0c4ebfbbb3 100644 --- a/packages/editor/src/core/extensions/table/table/table.ts +++ b/packages/editor/src/core/extensions/table/table/table.ts @@ -111,12 +111,15 @@ export const Table = Node.create({ ({ rows = 3, cols = 3, withHeaderRow = false } = {}) => ({ tr, dispatch, editor }) => { const node = createTable(editor.schema, rows, cols, withHeaderRow); - if (dispatch) { - const offset = tr.selection.anchor + 1; - tr.replaceSelectionWith(node) + if (dispatch) { + const { selection } = tr; + const position = selection.$from.before(selection.$from.depth); + + // Insert the table at the calculated position + tr.insert(position, node) .scrollIntoView() - .setSelection(TextSelection.near(tr.doc.resolve(offset))); + .setSelection(TextSelection.near(tr.doc.resolve(position + 1))); } return true;