Ace Editor - Change CTRL+H keybinding

只谈情不闲聊 提交于 2019-12-01 02:31:06

问题


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.


回答1:


Replace command is defined here. it is possible to use the following code to change Ctrl+H for Ctrl+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)
             }
         });
    }
});

but the part with inner command is quite ugly, i'd suggest to make an issue on ace repository to either use normal name for it, or pick up replace commands key automatically




回答2:


This worked for me:

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
});


来源:https://stackoverflow.com/questions/17633324/ace-editor-change-ctrlh-keybinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!