无法在角度4+中获得quilljs编辑器ENTER键按下事件监听器

问题描述 投票:2回答:1

我读到了关于addbinding from official quilljs dicumentation here但是我无法获得ENTER键按下事件监听器,尝试了其他键和BACKSPACE并且它们按预期工作但是ENTER键事件监听器不起作用。我跟随相关的帖子here in so但不能理解,任何人都可以提供一个例子或解释一下如何在配置中添加输入键的事件监听器?

到目前为止我尝试过的,

quill.keyboard.addBinding({
  key: Keyboard.keys.ENTER,
}, function(range, context) {
  console.log("enter clicked");
});

--

quill.keyboard.addBinding({
  key: 13,
}, function(range, context) {
  console.log("enter clicked");
});

--

quill.keyboard.addBinding({
  key: 'enter',
}, function(range, context) {
  console.log("enter clicked");
});
angular quilljs
1个回答
2
投票

我想出了你的问题。对于像enter和tab这样的特殊键,你必须覆盖标准的quill文档。我是这样做的:

bindings = {
    enter: {
      key: 13,
      handler: function() {
        console.log('enter pressed');
        this.hideSymbols = !this.hideSymbols;
        console.log(this.hideSymbols);
      }
    }
  };

this.modules = {
      keyboard: {
        bindings: this.bindings
      },
      formula: true,
      toolbar: true,
      counter: { container: '#counter', unit: 'word' },
      equalsSymbol: { container: '#equalsBtn', selector: 'equals' },
      impliesSymbol: { container: '#impliesBtn', selector: 'implies' }
    };

所以基本上只需要创建自己的绑定对象,并在模块中调用构造函数,就像我一样将自定义绑定添加到键盘。

© www.soinside.com 2019 - 2024. All rights reserved.