Esempio n. 1
0
CLI.prototype._bindKeys = function(key_bindings) {
  var handler = new HashHandler();
  for(var i = 0; i < key_bindings.length; i++){
    handler.bindKeys(key_bindings[i]);
  }
  this._editor.keyBinding.addKeyboardHandler(handler);
};
Esempio n. 2
0
    addSearchKeyboardHandler: function(txtFind, type) {
        var _self = this;
        var HashHandler = require("ace/keyboard/hash_handler").HashHandler;

        txtFind.ace.session.listName = type;
        var iSearchHandler = new HashHandler();
        iSearchHandler.bindKeys({
            "Up": function(codebox) {
                if (codebox.getCursorPosition().row > 0)
                    return false;

                _self.keyStroke = "next";
                _self.navigateList(_self.keyStroke, codebox);
                codebox.selection.moveCursorFileStart();
                codebox.selection.clearSelection();
            },
            "Down": function(codebox) {
                if (codebox.getCursorPosition().row < codebox.session.getLength() - 1)
                    return false;

                _self.keyStroke = "prev";
                _self.navigateList(_self.keyStroke, codebox);
                codebox.selection.lead.row = codebox.session.getLength() - 1;
            },
            "Ctrl-Home":  function(codebox) { _self.keyStroke = "prev"; _self.navigateList("first", codebox); },
            "Ctrl-End": function(codebox) {   _self.keyStroke = "next"; _self.navigateList("last", codebox);  },
            "Esc": function() { _self.toggleDialog(-1);},
            "Shift-Esc|Ctrl-Esc": function() { _self.restore(); },
            "Ctrl-Return|Alt-Return": function(codebox) { codebox.insert("\n");},
            "Return": function(codebox) {
                _self.saveHistory(codebox.session.getValue());
                _self.execFind(false, false, true, true);
            },
            "Shift-Return": function(codebox) {
                _self.saveHistory(codebox.session.getValue());
                _self.execFind(false, true, true, true);
            }
        });

        iSearchHandler.handleKeyboard = function(data, hashId, keyString, keyCode) {
            if (keyString == "\x00")
                return;
            var command = this.findKeyCommand(hashId, keyString)
            var editor = data.editor;
            if (!command)
                return;

            var success = command.exec(editor);
            if (success != false)
                return {command: "null"};
        };
        txtFind.ace.setKeyboardHandler(iSearchHandler);
        return iSearchHandler;
    },
Esempio n. 3
0
        this.handleKeyboard = function(data, hashId, keyString, keyCode, ev) {
            var term = data.editor.session.term;
            if (hashId == -1) {
                this.send(keyString);
                return {command: "null"};
            }
            if (term.applicationKeypad) {
                if (applicationKeys[keyString]) {
                    this.send(applicationKeys[keyString]);
                    return {command: "null"};
                }
            }
            var key = specialKeys.findKeyCommand(hashId, keyString);
            if (typeof key == "string") {
                this.send(key);
                return {command: "null"};
            } else if (key && key.command) {
                return key;
            } else if (key && key.exec) {
                if (!key.isAvailable || key.isAvailable(ace))
                    return {command: key};
            } else if (key && key.name) {
                this.send(key.name);
                return {command: "null"};
            }
            
            key = defaultHandler(ev);
            if (key)
                this.send(key);

            return {
                command: "null",
                passEvent: !hashId || hashId === KEY_MODS.shift || (
                    specialKeys.platform === "mac" && hashId === KEY_MODS.option
                )
            };
        };
Esempio n. 4
0
    module.exports = function initInput(ace) {
        var HashHandler = require("ace/keyboard/hash_handler").HashHandler;
        var KEY_MODS = require("ace/lib/keys").KEY_MODS;
        var specialKeys = new HashHandler();
        // http://www.math.utah.edu/docs/info/features_7.html
        specialKeys.bindKeys({
            "Shift-PageUp"      : {command: "pageup"},
            "Shift-PageDown"    : {command: "pagedown"},
            "Ctrl-Up"           : {command: "scrollup"},
            "Ctrl-Down"         : {command: "scrolldown"},

            "Backspace"         : '\x7f',
            "Shift-Backspace"   : '\x08',
            "Alt-Backspace"     : '\x1b\x7f',
            "Tab"               : '\t',
            "Shift-Tab"         : '\x1b[Z',
            "Return"            : '\r',
            "Escape"            : '\x1b',
            "Left"              : '\x1b[D',
            "Ctrl-Left"         : '\x1b[5D',
            "Right"             : '\x1b[C',
            "Ctrl-Right"        : '\x1b[5C',
            "Up"                : '\x1b[A',
            "Down"              : '\x1b[B',
            "Delete"            : '\x1b[3~',
            "Insert"            : '\x1b[2~',
            "Home"              : '\x1b[1~',
            "End"               : '\x1b[4~',
            "PageUp"            : '\x1b[5~',
            "pageDown"          : '\x1b[6~',
            "F1"                : '\x1bOP',
            "F2"                : '\x1bOQ',
            "F3"                : '\x1bOR',
            "F4"                : '\x1bOS',
            "F5"                : '\x1b[15~',
            "F6"                : '\x1b[17~',
            "F7"                : '\x1b[18~',
            "F8"                : '\x1b[19~',
            "F9"                : '\x1b[20~',
            "F10"               : '\x1b[21~',
            "F11"               : '\x1b[23~',
            "F12"               : '\x1b[24~'
        });
        
        // make shell to behave more like regular editor
        var aliases = [{
            bindKey: {win: "Ctrl-left", mac: "Option-left"},
            name: "\u001bb" // "alt-b"
        }, {
            bindKey: {win: "Ctrl-right", mac: "Option-right"},
            name: "\u001bf" //"alt-b"
        }, {
            bindKey: {win: "Ctrl-Delete", mac: "Option-Delete"},
            name: "\u001bd" //"alt-d"
        }, {
            bindKey: {win: "Ctrl-Backspace", mac: "Option-Backspace"},
            name: "\x1b\x7f" //"alt-backspace"
        }, {
            bindKey: {win: "Ctrl-Delete", mac: "Option-Delete"},
            name: "\u001bd" //"alt-d"
        }, {
            bindKey: {win: "Alt-Backspace", mac: "Ctrl-Backspace"},
            name: "\u0017" //"ctrl-w"
        }, {
            bindKey: {win: "Alt-Backspace", mac: "Ctrl-Backspace"},
            name: "\u0017" //"ctrl-w"
        }, {
            bindKey: {win: "Ctrl-z", mac: "Cmd-z"},
            name: "\u0018\u0015" //"ctrl-x ctrl-u"
        }];
        
        specialKeys.addCommands(aliases);
        // SS3 as ^[O for 7-bit  '\x8fD';  SS3 as 0x8f for 8-bit
        var applicationKeys = {
            "left":      '\x1bOD',
            "right":     '\x1bOC',
            "up":        '\x1bOA',
            "down":      '\x1bOB',
            "home":      '\x1bOH',
            "end":       '\x1bOF'
        };
        
        function defaultHandler(ev) {
            var key = null;
            var keyCode = ev.keyCode;
            var isControl = ev.ctrlKey;
            var isMeta = specialKeys.platform == "mac" ? ev.metaKey : ev.altKey;
            // a-z and space
            if (isControl) {
                if (keyCode >= 65 && keyCode <= 90) {
                    key = String.fromCharCode(keyCode - 64);
                } else if (keyCode === 32) {
                    // NUL
                    key = String.fromCharCode(0);
                } else if (keyCode >= 51 && keyCode <= 55) {
                    // escape, file sep, group sep, record sep, unit sep
                    key = String.fromCharCode(keyCode - 51 + 27);
                } else if (keyCode === 56) {
                    // delete
                    key = String.fromCharCode(127);
                } else if (keyCode === 219) {
                    // ^[ - escape
                    key = String.fromCharCode(27);
                } else if (keyCode === 221) {
                    // ^] - group sep
                    key = String.fromCharCode(29);
                }
            } else if (isMeta) {
                if (keyCode >= 65 && keyCode <= 90) {
                    key = '\x1b' + String.fromCharCode(keyCode + 32);
                } else if (keyCode === 192) {
                    key = '\x1b`';
                } else if (keyCode >= 48 && keyCode <= 57) {
                    key = '\x1b' + (keyCode - 48);
                }
            }
            return key;
        } 
        
        this.handleKeyboard = function(data, hashId, keyString, keyCode, ev) {
            var term = data.editor.session.term;
            if (hashId == -1) {
                this.send(keyString);
                return {command: "null"};
            }
            if (term.applicationKeypad) {
                if (applicationKeys[keyString]) {
                    this.send(applicationKeys[keyString]);
                    return {command: "null"};
                }
            }
            var key = specialKeys.findKeyCommand(hashId, keyString);
            if (typeof key == "string") {
                this.send(key);
                return {command: "null"};
            } else if (key && key.command) {
                return key;
            } else if (key && key.exec) {
                if (!key.isAvailable || key.isAvailable(ace))
                    return {command: key};
            } else if (key && key.name) {
                this.send(key.name);
                return {command: "null"};
            }
            
            key = defaultHandler(ev);
            if (key)
                this.send(key);

            return {
                command: "null",
                passEvent: !hashId || hashId === KEY_MODS.shift || (
                    specialKeys.platform === "mac" && hashId === KEY_MODS.option
                )
            };
        };

        var isCopyAvailable = function(ed) {
            if (ed && !ed.getCopyText)
                ed = ed.ace || ed.$editor;
            return ed && !!ed.getCopyText();
        };
        specialKeys.addCommands([{
            name: "copy",
            bindKey: {mac: "Cmd-c", win: "Ctrl-c"},
            exec: function() { return false },
            isAvailable: isCopyAvailable
        },{
            name: "cut",
            bindKey: {mac: "Cmd-x", win: "Ctrl-x"},
            exec: function() { return false },
            isAvailable: isCopyAvailable
        },{
            name: "paste",
            bindKey: {mac: "Cmd-v", win: "Ctrl-v"},
            exec: function() { return false },
            isAvailable: function(ed) {
                return true;
            }
        },{
            name: "clear",
            bindKey: {mac: "Cmd-K", win: "Ctrl-K"},
            exec: function(ed) {
                var term = ed.ace.session.term;
                term.clear();
                term.send("\x0c"); //"ctrl-l"
            },
            isAvailable: function(editor) {
                return true; // todo disable in vim?
            }
        }]);
        
        ace.onPaste = function(text) {
            this.send(text);
        };
        
        ace.setKeyboardHandler(this);
        ace.keyBinding.addKeyboardHandler(ace.commands);
        ace.commands.commandKeyBinding = {};
        
        this.send = ace.send = function(text) {
            ace.session.send && ace.session.send(text);
            
        };
        return specialKeys;
    };
Esempio n. 5
0
     addSearchKeyboardHandler: function(txtFind, type) {
         var _self = this;
         txtFind.ace.saveHistory = function() {
             _self.saveHistory(this.getValue(), this.session.listName);
         };
 
         txtFind.ace.session.listName = type;
         var iSearchHandler = new HashHandler();
         iSearchHandler.bindKeys({
             "Up": function(codebox) {
                 if (codebox.getCursorPosition().row > 0)
                     return false;
 
                 _self.navigateList("next", codebox);
                 codebox.selection.moveCursorFileStart();
                 codebox.selection.clearSelection();
             },
             "Down": function(codebox) {
                 if (codebox.getCursorPosition().row < codebox.session.getLength() - 1)
                     return false;
 
                 _self.navigateList("prev", codebox);
                 codebox.selection.lead.row = codebox.session.getLength() - 1;
             },
             "Ctrl-Home": function(codebox) { _self.navigateList("first", codebox); },
             "Ctrl-End": function(codebox) { _self.navigateList("last", codebox); },
             "Esc": function() { toggleDialog(-1); },
             "Shift-Esc": function() { restore(); },
             "Ctrl-Return|Alt-Return": function(codebox) { codebox.insert("\n"); },
             "Return": function(codebox) {
                 execFind(false, true);
             },
             "Shift-Return": function(codebox) {
                 execFind(true, true);
             }
         });
         
         function optionCommand(name, key) {
             return {
                 bindKey: {
                     mac: key.replace(/^|\|/g, "$&Ctrl-Option-"),
                     win: key.replace(/^|\|/g, "$&Alt-")
                 },
                 name: name,
                 exec: toggleOption
             };
         }
         
         toggleOption && iSearchHandler.addCommands([
             optionCommand("regex", "r"),
             optionCommand("matchCase", "i|c"),
             optionCommand("wholeWords", "w|b"),
             optionCommand("preserveCase", "a")
         ]);
         
         iSearchHandler.handleKeyboard = function(data, hashId, keyString, keyCode) {
             if (keyString == "\x00")
                 return;
             var command = this.findKeyCommand(hashId, keyString);
             var editor = data.editor;
             if (!command)
                 return;
 
             var success = editor.execCommand(command);
             if (success !== false)
                 return { command: "null" };
         };
         txtFind.ace.setKeyboardHandler(iSearchHandler);
         return iSearchHandler;
     },