28 lines
973 B
TypeScript
28 lines
973 B
TypeScript
import { Extension } from '@tiptap/core'
|
|
|
|
/**
|
|
* Extension TipTap qui permet de transformer instantanément le bloc sous le curseur
|
|
* en cyclant entre Titre 1, Titre 2, Titre 3 et Paragraphe normal via le raccourci clavier Cmd+Shift+H (ou Ctrl+Shift+H).
|
|
*/
|
|
export const TurnIntoShortcutExtension = Extension.create({
|
|
name: 'turnIntoShortcut',
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-Shift-h': () => {
|
|
const { editor } = this
|
|
|
|
if (editor.isActive('heading', { level: 1 })) {
|
|
return editor.chain().focus().toggleHeading({ level: 2 }).run()
|
|
} else if (editor.isActive('heading', { level: 2 })) {
|
|
return editor.chain().focus().toggleHeading({ level: 3 }).run()
|
|
} else if (editor.isActive('heading', { level: 3 })) {
|
|
return editor.chain().focus().setParagraph().run()
|
|
} else {
|
|
return editor.chain().focus().toggleHeading({ level: 1 }).run()
|
|
}
|
|
},
|
|
}
|
|
},
|
|
})
|