ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
27.8k stars 2.31k forks source link

[Bug]: Blockquote toggle shortcut not working #4005

Open yan-yanishevsky opened 1 year ago

yan-yanishevsky commented 1 year ago

Which packages did you experience the bug in?

extension-blockquote

What Tiptap version are you using?

2.0.0-beta.220

What’s the bug you are facing?

Mod-Shift-b doesn't toggle the Blockquote, it toggles Bold mark instead. Tried on https://tiptap.dev/examples/default example

But It works if I disable Bold extension or if I extend Blockquote extension like this

const CustomBlockquote = Blockquote.extend({
  addKeyboardShortcuts() {
    return {
      'Mod-Shift-B': () => this.editor.commands.toggleBlockquote(),
    }
  },
})

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

Blockquote keyboard shortcut should work

Anything to add? (optional)

No response

Did you update your dependencies?

Are you sponsoring us?

ashu12chi commented 1 year ago

The order of execution of keyboard shortcuts depends on the priority. Since currently pressing Ctrl+Shift+B will fall back to Ctrl+B if Ctrl+Shift+B has lower priority or can't be executed. (Ref: https://github.com/ueberdosis/tiptap/issues/4006)

The default priority of all extensions is 100. (Ref: https://tiptap.dev/guide/custom-extensions/#priority) To make this shortcut work, you can increase the priority of the blockquote extension to 101.

const CustomBlockquote = Blockquote.extend({
  priority: 101,
  addKeyboardShortcuts() {
    return {
      'Mod-Shift-B': () => this.editor.commands.toggleBlockquote(),
    }
  },
})
yan-yanishevsky commented 1 year ago

Hmm, I didn't know this also affects shortcuts. So I guess the problem is in StarterKit extension, where Blockquote goes before Bold extension (as I know the order in extensions array also affects the order of their execution). Not sure if it is intentional. Changing priority is also a solution, thanks