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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user