fix focus for tables
This commit is contained in:
@@ -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 don’t 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)
|
||||
|
||||
6
packages/core/src/helpers/isTextSelection.ts
Normal file
6
packages/core/src/helpers/isTextSelection.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user