我在这里阅读了官方 quilljs dicumentation 中的 addbinding,但我无法获得 ENTER 按键事件侦听器,尝试了其他键和 BACKSPACE 并且它们按预期工作,但 ENTER 键事件侦听器不起作用。我在这里关注相关帖子,但无法理解,谁能提供一个示例或解释一下如何为配置中的输入键添加事件侦听器?
我到目前为止所尝试的,
quill.keyboard.addBinding({
key: Keyboard.keys.ENTER,
}, function(range, context) {
console.log("enter clicked");
});
Run Code Online (Sandbox Code Playgroud)
——
quill.keyboard.addBinding({
key: 13,
}, function(range, context) {
console.log("enter clicked");
});
Run Code Online (Sandbox Code Playgroud)
——
quill.keyboard.addBinding({
key: 'enter',
}, function(range, context) {
console.log("enter clicked");
});
Run Code Online (Sandbox Code Playgroud)
我想出了你的问题。对于像 enter 和 tab 这样的特殊键,你必须覆盖标准的 quill 文档。我是这样做的:
bindings = {
enter: {
key: 13,
handler: function() {
console.log('enter pressed');
this.hideSymbols = !this.hideSymbols;
console.log(this.hideSymbols);
}
}
};Run Code Online (Sandbox Code Playgroud)
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' }
};Run Code Online (Sandbox Code Playgroud)
所以基本上只需创建自己的绑定对象,并在构造函数中的模块调用中像我一样将自定义绑定添加到键盘。