mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix(core) Nested chain not preserving dispatch state (#4152)
* Fix nested chain not preserving dispatch state * Change test to read as sentence
This commit is contained in:
parent
b24df3aa4c
commit
26610cdff3
@ -133,7 +133,7 @@ export class CommandManager {
|
||||
transaction: tr,
|
||||
}),
|
||||
dispatch: shouldDispatch ? () => undefined : undefined,
|
||||
chain: () => this.createChain(tr),
|
||||
chain: () => this.createChain(tr, shouldDispatch),
|
||||
can: () => this.createCan(tr),
|
||||
get commands() {
|
||||
return Object.fromEntries(
|
||||
|
@ -167,4 +167,32 @@ describe('can', () => {
|
||||
|
||||
expect(canSetMarkToBold).to.eq(true)
|
||||
})
|
||||
|
||||
it('builds and passes down an undefined dispatch for nested "can" chain', () => {
|
||||
const editor = new Editor({
|
||||
extensions: [Document, Paragraph, Text, History],
|
||||
})
|
||||
|
||||
let capturedOuterDispatch: ((args?: any) => any) | undefined
|
||||
let capturedInnerDispatch: ((args?: any) => any) | undefined
|
||||
|
||||
editor
|
||||
.can()
|
||||
.chain()
|
||||
.command(({ chain, dispatch: outterDispatch }) => {
|
||||
capturedOuterDispatch = outterDispatch
|
||||
return chain()
|
||||
.command(({ dispatch: innerDispatch }) => {
|
||||
capturedInnerDispatch = innerDispatch
|
||||
return true
|
||||
})
|
||||
.run()
|
||||
})
|
||||
.run()
|
||||
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
expect(capturedOuterDispatch).to.be.undefined
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
expect(capturedInnerDispatch).to.be.undefined
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user