Listen to key press Enter in Quill.js

旧巷老猫 提交于 2019-12-06 12:13:17

问题


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:


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.



来源:https://stackoverflow.com/questions/48775485/listen-to-key-press-enter-in-quill-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!