Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: keyboard shortcuts fire in reverse order based on priority #1547

Closed
thatsjonsense opened this issue Jul 6, 2021 · 2 comments
Closed
Assignees
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor Type: Bug The issue or pullrequest is related to a bug

Comments

@thatsjonsense
Copy link
Contributor

Description
If I have two extensions that both register the same shortcut, the one with the lower priority takes precedence. The docs say it should be higher.

The issue is with this line:

I don't understand why it's reversing. The extensions are sorted from highest priority to low, but this reverses them for adding plugins.

According to ProseMirror keymap docs:

The order in which they appear determines their precedence (the ones early in the array get to dispatch first).

Because we're reversing, the highest priority extensions are dispatching last.

@thatsjonsense thatsjonsense added Type: Bug The issue or pullrequest is related to a bug v2 labels Jul 6, 2021
@hanspagel hanspagel added the sponsor 💖 This issue or pull request was created by a Tiptap sponsor label Jul 6, 2021
@SF-Simon
Copy link

SF-Simon commented Aug 2, 2021

I was also misled by this at that time. Later, when I looked at other components, I found that the smaller the more advanced it was.

However, at present, if it is to be executed in reverse order, I believe it should not be necessary, but the documents should be updated in time.

@philippkuehn
Copy link
Contributor

philippkuehn commented Aug 2, 2021

This is how order should work at the moment:

  • extensions with a higher priority should run first
  • after that plugins are executed in reverse order
const ExtensionOne = Extension.create({
  priority: 1,
  addProseMirrorPlugins() {
    return [
      new Plugin(), // 4.
      new Plugin(), // 3.
    ]
  },
})

const ExtensionOne = Extension.create({
  priority: 2,
  addProseMirrorPlugins() {
    return [
      new Plugin(), // 2.
      new Plugin(), // 1.
    ]
  },
})

new Editor({
  extensions: [
    ExtensionOne,
    ExtensionTwo,
  ],
})

I reverse the order of addProseMirrorPlugins because I implemented a system of extending extensions so the extended ones should be executed first.

const Extended= Extension.extend({
  addProseMirrorPlugins() {
    return [
      ...this.parent(), // previous plugins
      new Plugin(), // new plugin should run first because you maybe want to overwrite something
    ]
  },
})

Keyboard shortcuts should also run first for extensions with a higher priority.

Does this makes sense to you? If something doesn’t work like this it would be nice to have a codesandbox so I can check what is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

4 participants