Tiptap: Is it possible to prevent new line by enter?

Created on 14 May 2019  路  2Comments  路  Source: ueberdosis/tiptap

Describe the bug
Right now when I tap Enter there is new line appear, is it possible to call some other action and prevent new line?

Steps to Reproduce / Codesandbox Example
Steps to reproduce the behavior:
Open https://tiptap.scrumpy.io/history
Click Enter

Expected behavior
I want to call another action by clicking on Enter

question

Most helpful comment

I'm not sure why you labeled this as a bug, but you can create a custom Extension for it.

import { Extension, Plugin } from 'tiptap'

export default class EnterHandler extends Extension {

  get name() {
    return 'enter_handler'
  }

  get plugins() {
    return [
      new Plugin({
        props: {
          handleKeyDown: (view, event) => {
            if (event.key === 'Enter' && !event.shiftKey) {
              // do something
              return true
            }

            return false
          },
        },
      }),
    ]
  }

}

All 2 comments

I'm not sure why you labeled this as a bug, but you can create a custom Extension for it.

import { Extension, Plugin } from 'tiptap'

export default class EnterHandler extends Extension {

  get name() {
    return 'enter_handler'
  }

  get plugins() {
    return [
      new Plugin({
        props: {
          handleKeyDown: (view, event) => {
            if (event.key === 'Enter' && !event.shiftKey) {
              // do something
              return true
            }

            return false
          },
        },
      }),
    ]
  }

}

Yes, it works! Thanks a lot, specially for quick response.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agentq15 picture agentq15  路  3Comments

santicros picture santicros  路  3Comments

chrisjbrown picture chrisjbrown  路  3Comments

unikitty37 picture unikitty37  路  3Comments

pk-pressf1 picture pk-pressf1  路  3Comments