fix: fix order of executed plugins, fix #1547
This commit is contained in:
@@ -205,8 +205,12 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get plugins(): Plugin[] {
|
get plugins(): Plugin[] {
|
||||||
return [...this.extensions]
|
// With ProseMirror, first plugins within an array are executed first.
|
||||||
.reverse()
|
// In tiptap, we provide the ability to override plugins,
|
||||||
|
// so it feels more natural to run plugins at the end of an array first.
|
||||||
|
// That’s why we have to reverse the `extensions` array and sort again
|
||||||
|
// based on the `priority` option.
|
||||||
|
return ExtensionManager.sort([...this.extensions].reverse())
|
||||||
.map(extension => {
|
.map(extension => {
|
||||||
const context = {
|
const context = {
|
||||||
name: extension.name,
|
name: extension.name,
|
||||||
|
|||||||
69
tests/cypress/integration/core/pluginOrder.spec.ts
Normal file
69
tests/cypress/integration/core/pluginOrder.spec.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
|
import { Editor, Extension } from '@tiptap/core'
|
||||||
|
import Document from '@tiptap/extension-document'
|
||||||
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
|
import Text from '@tiptap/extension-text'
|
||||||
|
|
||||||
|
describe('pluginOrder', () => {
|
||||||
|
it('should run keyboard shortcuts in correct order', () => {
|
||||||
|
const order: number[] = []
|
||||||
|
|
||||||
|
cy.window().then(({ document }) => {
|
||||||
|
const element = document.createElement('div')
|
||||||
|
|
||||||
|
document.body.append(element)
|
||||||
|
|
||||||
|
const editor = new Editor({
|
||||||
|
element,
|
||||||
|
extensions: [
|
||||||
|
Document,
|
||||||
|
Paragraph,
|
||||||
|
Text,
|
||||||
|
Extension.create({
|
||||||
|
priority: 1000,
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
a: () => {
|
||||||
|
order.push(1)
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Extension.create({
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
a: () => {
|
||||||
|
order.push(3)
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
Extension.create({
|
||||||
|
addKeyboardShortcuts() {
|
||||||
|
return {
|
||||||
|
a: () => {
|
||||||
|
order.push(2)
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
cy.get('.ProseMirror')
|
||||||
|
.type('a')
|
||||||
|
.wait(100).then(() => {
|
||||||
|
expect(order).to.deep.eq([1, 2, 3])
|
||||||
|
|
||||||
|
editor.destroy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user