add autofocus option

This commit is contained in:
Philipp Kühn
2020-08-21 17:44:02 +02:00
parent 71c3927b28
commit a4a4ff31e5
2 changed files with 7 additions and 3 deletions

View File

@@ -16,14 +16,14 @@ interface ResolvedSelection {
to: number,
}
type Position = 'start' | 'end' | number | null
type Position = 'start' | 'end' | number | boolean | null
function resolveSelection(editor: Editor, position: Position = null): ResolvedSelection {
if (position === null) {
return editor.selection
}
if (position === 'start') {
if (position === 'start' || position === true) {
return {
from: 0,
to: 0,
@@ -48,7 +48,7 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
export default (next: Function, editor: Editor) => async (position = null) => {
const { view, state } = editor
if ((view.hasFocus() && position === null)) {
if ((view.hasFocus() && position === null) || position === false) {
next()
return
}