fix focus for tables

This commit is contained in:
Philipp Kühn
2021-01-22 23:56:33 +01:00
parent aef9d1ca41
commit 605ead820f
2 changed files with 13 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import { EditorState, TextSelection } from 'prosemirror-state'
import { Command, FocusPosition } from '../types'
import minMax from '../utilities/minMax'
import isTextSelection from '../helpers/isTextSelection'
function resolveSelection(state: EditorState, position: FocusPosition = null) {
if (!position) {
@@ -42,6 +43,12 @@ export const focus = (position: FocusPosition = null): Command => ({
return true
}
// we dont try to resolve a NodeSelection or CellSelection
if (dispatch && position === null && !isTextSelection(editor.state.selection)) {
view.focus()
return true
}
const { from, to } = resolveSelection(editor.state, position) || editor.state.selection
const { doc } = tr
const resolvedFrom = minMax(from, 0, doc.content.size)

View File

@@ -0,0 +1,6 @@
import { TextSelection } from 'prosemirror-state'
import isObject from '../utilities/isObject'
export default function isTextSelection(value: unknown): value is TextSelection {
return isObject(value) && value instanceof TextSelection
}