use last selection + 1 to set table create selection

This commit is contained in:
Chrissi2812 2019-10-17 14:15:36 +02:00
parent 8cce2508a9
commit 3591b5fa82
No known key found for this signature in database
GPG Key ID: B4B82C7E618271DA

View File

@ -42,11 +42,12 @@ export default class Table extends Node {
return { return {
createTable: ({ rowsCount, colsCount, withHeaderRow }) => ( createTable: ({ rowsCount, colsCount, withHeaderRow }) => (
(state, dispatch) => { (state, dispatch) => {
const offset = state.tr.selection.anchor + 1
const nodes = createTable(schema, rowsCount, colsCount, withHeaderRow) const nodes = createTable(schema, rowsCount, colsCount, withHeaderRow)
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView() const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView()
const resolvedPos = tr.doc.resolve(offset)
// get selection for first cell
const resolvedPos = tr.doc.resolve(tr.selection.anchor - nodes.content.size)
tr.setSelection(TextSelection.near(resolvedPos)) tr.setSelection(TextSelection.near(resolvedPos))
dispatch(tr) dispatch(tr)