From 8cce2508a9aad73fd2597539b20f1e89cd462a67 Mon Sep 17 00:00:00 2001 From: Chrissi2812 Date: Wed, 2 Oct 2019 15:47:41 +0200 Subject: [PATCH] set selection to first cell after table insert fixes #447 --- packages/tiptap-extensions/src/nodes/Table.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/tiptap-extensions/src/nodes/Table.js b/packages/tiptap-extensions/src/nodes/Table.js index 905407574..fcc8d8035 100644 --- a/packages/tiptap-extensions/src/nodes/Table.js +++ b/packages/tiptap-extensions/src/nodes/Table.js @@ -19,6 +19,7 @@ import { fixTables, } from 'prosemirror-tables' import { createTable } from 'prosemirror-utils' +import { TextSelection } from 'prosemirror-state' import TableNodes from './TableNodes' export default class Table extends Node { @@ -43,6 +44,11 @@ export default class Table extends Node { (state, dispatch) => { const nodes = createTable(schema, rowsCount, colsCount, withHeaderRow) const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView() + + // get selection for first cell + const resolvedPos = tr.doc.resolve(tr.selection.anchor - nodes.content.size) + tr.setSelection(TextSelection.near(resolvedPos)) + dispatch(tr) } ),