Skip to content

How to hook into handleKeyDown from extension in tiptap v2 ? #1249

Discussion options

You must be logged in to vote

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;
          },
        },
      }),
    ]
  }
})

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pymarco
Comment options

@philippkuehn
Comment options

Answer selected by pymarco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants