7

I'm working on an implementation of Ace Editor and Ctrl+F works great for the built-in "Find" dialog, however I'm trying to find a way to change out the Ctrl+H for Ctrl+R and prevent default behavior.

I've looked over docs and forums about working with the keybindings but I can't identify what method is being called to instantiate the 'replace' dialog or how to overwrite it.

4

2 回答 2

14

替换命令在这里定义。可以使用以下代码将Ctrl+更改HCtrl+R

editor.commands.addCommand({
    name: "replace",
    bindKey: {win: "Ctrl-R", mac: "Command-Option-F"},
    exec: function(editor) {
        require("ace/config").loadModule("ace/ext/searchbox", function(e) {
             e.Search(editor, true)  
             // take care of keybinding inside searchbox           
             // this is too hacky :(             
             var kb = editor.searchBox.$searchBarKb
             command = kb.commandKeyBinding["ctrl-h"]
             if (command && command.bindKey.indexOf("Ctrl-R") == -1) {
                 command.bindKey += "|Ctrl-R"
                 kb.addCommand(command)
             }
         });
    }
});

但是内部命令的部分非常难看,我建议在 ace 存储库上提出问题,要么使用正常名称,要么replace自动获取命令键

于 2013-07-14T03:06:03.067 回答
0

这对我有用:

editor.commands.addCommand({
name: 'replace',
bindKey: {win: 'Ctrl-R', mac: 'Command-Option-F'},
exec: function(editor) {
ace.config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)});
},
readOnly: true
});
于 2015-06-01T19:33:17.270 回答