mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 19:29:02 +08:00
Merge pull request #474 from Chrissi2812/issue-447
set selection to first cell after table insert
This commit is contained in:
commit
6bfeb19043
@ -19,6 +19,7 @@ import {
|
|||||||
fixTables,
|
fixTables,
|
||||||
} from 'prosemirror-tables'
|
} from 'prosemirror-tables'
|
||||||
import { createTable } from 'prosemirror-utils'
|
import { createTable } from 'prosemirror-utils'
|
||||||
|
import { TextSelection } from 'prosemirror-state'
|
||||||
import TableNodes from './TableNodes'
|
import TableNodes from './TableNodes'
|
||||||
|
|
||||||
export default class Table extends Node {
|
export default class Table extends Node {
|
||||||
@ -43,6 +44,11 @@ export default class Table extends Node {
|
|||||||
(state, dispatch) => {
|
(state, dispatch) => {
|
||||||
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()
|
||||||
|
|
||||||
|
// get selection for first cell
|
||||||
|
const resolvedPos = tr.doc.resolve(tr.selection.anchor - nodes.content.size)
|
||||||
|
tr.setSelection(TextSelection.near(resolvedPos))
|
||||||
|
|
||||||
dispatch(tr)
|
dispatch(tr)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user