fix: add way to cancel inputrules and pasterules (#2368)

Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
This commit is contained in:
Philipp Kühn
2022-01-10 14:43:56 +01:00
committed by GitHub
parent 5144a6cd1b
commit 669efd00e9
10 changed files with 112 additions and 86 deletions

View File

@@ -1,4 +1,9 @@
import { EditorState, Plugin, TextSelection } from 'prosemirror-state'
import {
EditorState,
Plugin,
TextSelection,
Transaction,
} from 'prosemirror-state'
import { Editor } from './Editor'
import { CommandManager } from './CommandManager'
import { createChainableState } from './helpers/createChainableState'
@@ -33,7 +38,7 @@ export class InputRule {
commands: SingleCommands,
chain: () => ChainedCommands,
can: () => CanCommands,
}) => void
}) => Transaction | null
constructor(config: {
find: InputRuleFinder,
@@ -44,7 +49,7 @@ export class InputRule {
commands: SingleCommands,
chain: () => ChainedCommands,
can: () => CanCommands,
}) => void,
}) => Transaction | null,
}) {
this.find = config.find
this.handler = config.handler
@@ -87,7 +92,7 @@ function run(config: {
text: string,
rules: InputRule[],
plugin: Plugin,
}): any {
}): boolean {
const {
editor,
from,
@@ -148,7 +153,7 @@ function run(config: {
state,
})
rule.handler({
const handler = rule.handler({
state,
range,
match,
@@ -158,7 +163,7 @@ function run(config: {
})
// stop if there are no changes
if (!tr.steps.length) {
if (!handler || !tr.steps.length) {
return
}