dont return tr in input rules and pasterules

This commit is contained in:
Philipp Kühn
2022-01-10 14:55:53 +01:00
parent 209108b700
commit 6a813686f5
9 changed files with 12 additions and 36 deletions

View File

@@ -1,9 +1,4 @@
import { import { EditorState, Plugin, TextSelection } from 'prosemirror-state'
EditorState,
Plugin,
TextSelection,
Transaction,
} from 'prosemirror-state'
import { Editor } from './Editor' import { Editor } from './Editor'
import { CommandManager } from './CommandManager' import { CommandManager } from './CommandManager'
import { createChainableState } from './helpers/createChainableState' import { createChainableState } from './helpers/createChainableState'
@@ -38,7 +33,7 @@ export class InputRule {
commands: SingleCommands, commands: SingleCommands,
chain: () => ChainedCommands, chain: () => ChainedCommands,
can: () => CanCommands, can: () => CanCommands,
}) => Transaction | null }) => void | null
constructor(config: { constructor(config: {
find: InputRuleFinder, find: InputRuleFinder,
@@ -49,7 +44,7 @@ export class InputRule {
commands: SingleCommands, commands: SingleCommands,
chain: () => ChainedCommands, chain: () => ChainedCommands,
can: () => CanCommands, can: () => CanCommands,
}) => Transaction | null, }) => void | null,
}) { }) {
this.find = config.find this.find = config.find
this.handler = config.handler this.handler = config.handler
@@ -163,7 +158,7 @@ function run(config: {
}) })
// stop if there are no changes // stop if there are no changes
if (!handler || !tr.steps.length) { if (handler === null || !tr.steps.length) {
return return
} }

View File

@@ -1,4 +1,4 @@
import { EditorState, Plugin, Transaction } from 'prosemirror-state' import { EditorState, Plugin } from 'prosemirror-state'
import { Editor } from './Editor' import { Editor } from './Editor'
import { CommandManager } from './CommandManager' import { CommandManager } from './CommandManager'
import { createChainableState } from './helpers/createChainableState' import { createChainableState } from './helpers/createChainableState'
@@ -34,7 +34,7 @@ export class PasteRule {
commands: SingleCommands, commands: SingleCommands,
chain: () => ChainedCommands, chain: () => ChainedCommands,
can: () => CanCommands, can: () => CanCommands,
}) => Transaction | null }) => void | null
constructor(config: { constructor(config: {
find: PasteRuleFinder, find: PasteRuleFinder,
@@ -45,7 +45,7 @@ export class PasteRule {
commands: SingleCommands, commands: SingleCommands,
chain: () => ChainedCommands, chain: () => ChainedCommands,
can: () => CanCommands, can: () => CanCommands,
}) => Transaction | null, }) => void | null,
}) { }) {
this.find = config.find this.find = config.find
this.handler = config.handler this.handler = config.handler
@@ -103,7 +103,7 @@ function run(config: {
state, state,
}) })
const handlers: (Transaction | null)[] = [] const handlers: (void | null)[] = []
state.doc.nodesBetween(from, to, (node, pos) => { state.doc.nodesBetween(from, to, (node, pos) => {
if (!node.isTextblock || node.type.spec.code) { if (!node.isTextblock || node.type.spec.code) {

View File

@@ -64,8 +64,6 @@ export function markInputRule(config: {
tr.removeStoredMark(config.type) tr.removeStoredMark(config.type)
} }
return tr
}, },
}) })
} }

View File

@@ -45,8 +45,6 @@ export function nodeInputRule(config: {
} else if (match[0]) { } else if (match[0]) {
tr.replaceWith(start, end, config.type.create(attributes)) tr.replaceWith(start, end, config.type.create(attributes))
} }
return tr
}, },
}) })
} }

View File

@@ -29,11 +29,7 @@ export function textInputRule(config: {
} }
} }
const { tr } = state state.tr.insertText(insert, start, end)
tr.insertText(insert, start, end)
return tr
}, },
}) })
} }

View File

@@ -29,12 +29,9 @@ export function textblockTypeInputRule(config: {
return null return null
} }
const { tr } = state state.tr
.delete(range.from, range.to)
tr.delete(range.from, range.to)
.setBlockType(range.from, range.from, config.type, attributes) .setBlockType(range.from, range.from, config.type, attributes)
return tr
}, },
}) })
} }

View File

@@ -54,8 +54,6 @@ export function wrappingInputRule(config: {
) { ) {
tr.join(range.from - 1) tr.join(range.from - 1)
} }
return tr
}, },
}) })
} }

View File

@@ -64,8 +64,6 @@ export function markPasteRule(config: {
tr.removeStoredMark(config.type) tr.removeStoredMark(config.type)
} }
return tr
}, },
}) })
} }

View File

@@ -29,11 +29,7 @@ export function textPasteRule(config: {
} }
} }
const { tr } = state state.tr.insertText(insert, start, end)
tr.insertText(insert, start, end)
return tr
}, },
}) })
} }