Listen to key press Enter in Quill.js

2019-04-15 10:53发布

According to the documentation, Quill can handle the Enter key but I can't make it work.

I have followed these steps listed on their site:

  1. Import Keyboard module: const Keyboard = Quill.import('modules/keyboard'); Quill.js Extension import documentation.
  2. Add the custom event called key binding. Quill.js Key binding documentation
  3. Call a function to handle the event.

My code is the following:

quill.keyboard.addBinding({ key: Keyboard.keys.ENTER, handler: function(range, context) { console.log('Enter Key!!!'); result.innerText = 'Key presset = ENTER'; } })

Code example

I have tried on Chrome (latest version) and Safari 11.0.3 on MacOS High Sierra 10.13.3

1条回答
2楼-- · 2019-04-15 11:23

Not sure if you want the Enter key or the Space key but you were on the right page with the Keyboard module but missed this key sentence:

The key is the JavaScript event key code, but string shorthands are allowed for alphanumeric keys and some common keys.

So you can either specify 13 or 'enter' if you meant the Enter key or 32 if you meant the Space key (sadly there is no shortcut for the Space key).

The upcoming 2.0 version (no public timeline) will also support the new easier to use KeyboardEvent.key but currently you should use keyCode.

查看更多
登录 后发表回答