简体   繁体   English

测验:如何处理自定义污点上的键盘事件

[英]Quill: How to handle keyboard events on custom blot

I've created custom inline-blot and want to handle keyboard events on it. 我已经创建了自定义内联污点,并希望处理其上的键盘事件。

In constructor i wrote code like this: constructor我编写了如下代码:

class FooBlot extends Inline {
  constructor(domNode, value){
    super(domNode, value);
    domNode.addEventListener('keydown', (event) => {this.keydown_handler(event)});
    domNode.addEventListener('click', (event) => {this.click_handler(event)});
  };

When i try to do something with my blot, only click event was handled, not keydown event. 当我尝试对印迹进行处理时,仅处理click事件,而不处理keydown事件。

You can see code example here . 您可以在此处查看代码示例。 Open console, click on sometext and you will see "clicked" in console. 打开控制台,单击一些文本 ,您将在控制台中看到“已单击”。 But if you try to press some keyboard buttons, eg arrows, you will not see anything. 但是,如果您尝试按一些键盘按钮,例如箭头,您将看不到任何东西。

What the right way to handle keyboard events on my custom blot? 在我的自定义污点上处理键盘事件的正确方法是什么?

The right way to handle keyboard events is to use Keyboard Module 处理键盘事件的正确方法是使用键盘模块

Simple example to handle Enter key: 处理Enter键的简单示例:

const bindings = {
  enter: {
    key: 13,
    shiftKey: null,
    handler: (range, context) => {
      // Handle enter
    }
  }
};

this.quill = new Quill('#editor-container', {
  modules: {
    keyboard: {
      bindings
    },
    toolbar: '#toolbar'
  },
  theme: 'snow'
});

UPDATE 更新

Another way: 其他方式:

quill.root.addEventListener('keydown', evt => { // Your code goes here });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM