How to hook into handleKeyDown from extension in tiptap v2 ? #1249
Answered
by
philippkuehn
marcusamargi
asked this question in
Questions & Help
-
When using Tiptap as the editor for entering a comment, I want the user to be able to submit by pressing enter. In v1 I had created an extension that emit an event via an event bus. This was done in handleKeyDown where I checked that the enter key was pressed. For Tiptap v2 and Vue 3, how can I access handleKeyDown ? Here's my extesion used with Tiptap v1.
|
Beta Was this translation helpful? Give feedback.
Answered by
philippkuehn
Apr 30, 2021
Replies: 1 comment 2 replies
-
This is how you do it in v2: // contrib
import { Extension } from '@tiptap/core'
import { Plugin } from 'prosemirror-state'
// project
import { EventBus } from './event-bus.js';
export const EnterHandler = Extension.create({
name: 'enter_handler',
addProseMirrorPlugins() {
return [
new Plugin({
props: {
handleKeyDown: (view, event) => {
if (event.key === 'Enter' && !event.shiftKey) {
EventBus.$emit("editor-enter");
return true;
}
return false;
},
},
}),
]
}
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
marcusamargi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is how you do it in v2: