如何防止浏览器覆盖我的ace编辑器的keyBindings? [英] How to prevent the browser to override my keyBindings of ace editor?

查看:132
本文介绍了如何防止浏览器覆盖我的ace编辑器的keyBindings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施了ace编辑器后出现了这个问题...

This question came up after i implemented the ace editor...

这是该链接:

Ace编辑器,如何删除所有keyBindings一个?

我有ace编辑器,并且for循环:

I have the ace editor, and thx to the for loop:

for (key in editor.keyBinding.$defaultHandler.commandKeyBinding) {
            if (key !== "ctrl-d")
                delete editor.keyBinding.$defaultHandler.commandKeyBinding[key];
        }

我有我自己的keyBindings,而ace编辑器也有自己的,我删除了,除了一个,其余所有都是,而那个是CTRL + D来删除一行...

I have my own keyBindings, and the ace editor has its own, witch i deleted, all but one, and that one is the CTRL+D to remove a line...

但是,我的浏览器在书签上已经有ctrl-d的内容了,现在我需要防止出现这种情况,有什么主意吗?

but, my browser has already the ctrl-d stuff on the bookmark, and i need now to prevent that, any ideas?

推荐答案

我在ace-editor中进行了测试,默认功能似乎会自行阻止默认键盘快捷键.但是为了回答您的问题,您可以使用ctrl + dcommand + d的事件侦听器,而不是使用e.preventDefault()e.stopPropagation()的事件侦听器...现在了解如何与ace-editor一起使用它:

I tested in ace-editor and default function seem to block default keyboard shortcuts on its own. but for the sake of answering your question, you can use an event listener for ctrl + d and command + d than use e.preventDefault() and e.stopPropagation()... now to how would you use it with ace-editor:

document.addEventListener("keydown", function(e) {
    if (e.key.toLowerCase() == "d" && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        editor.execCommand("removeline");
        e.preventDefault();
        e.stopPropagation();
    }
}, false);

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆