import { EditorState, TextSelection } from "prosemirror-state"; import { Command, CommandPredicate } from "./types"; import { getCursor } from "./util"; export function filter(predicate: CommandPredicate, command: Command): Command { return (state, dispatch) => { return predicate(state) ? command(state, dispatch) : false; }; } export function not(predicate: CommandPredicate): CommandPredicate { return state => !predicate(state); } export function startCursor(state: EditorState): boolean { const $cursor = getCursor(state); return $cursor != null && $cursor.parentOffset === 0; } export function textSelected(state: EditorState): boolean { const { selection } = state; return selection instanceof TextSelection && !selection.empty; }