refactoring

This commit is contained in:
Philipp Kühn
2020-11-17 19:36:27 +01:00
parent 4f36f30c75
commit ad3418e1d2
2 changed files with 10 additions and 7 deletions

View File

@@ -1,16 +1,14 @@
import { TextSelection } from 'prosemirror-state'
import { Editor } from '../Editor'
import { Command } from '../types'
import { Command, FocusPosition } from '../types'
import minMax from '../utils/minMax'
type Position = 'start' | 'end' | number | boolean | null
interface ResolvedSelection {
from: number,
to: number,
}
function resolveSelection(editor: Editor, position: Position = null): ResolvedSelection {
function resolveSelection(editor: Editor, position: FocusPosition = null): ResolvedSelection {
if (position === null) {
return editor.selection
}
@@ -37,8 +35,11 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
}
}
export default (position: Position = null): Command => ({
editor, view, tr, dispatch,
export default (position: FocusPosition = null): Command => ({
editor,
view,
tr,
dispatch,
}) => {
if ((view.hasFocus() && position === null) || position === false) {
return true

View File

@@ -14,7 +14,7 @@ export interface EditorOptions {
content: EditorContent,
extensions: Extensions,
injectCSS: boolean,
autofocus: 'start' | 'end' | number | boolean | null,
autofocus: FocusPosition,
editable: boolean,
onInit: () => void,
onUpdate: () => void,
@@ -116,3 +116,5 @@ export type ChainedCommands = {
}
export type CanCommands = SingleCommands & { chain: () => ChainedCommands }
export type FocusPosition = 'start' | 'end' | number | boolean | null