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

View File

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