From 345e085feeaaf5de40b28bb70ddeea904eb07048 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Thu, 16 Sep 2010 11:09:18 +0200 Subject: [PATCH 1/3] adapt web socket debugger service to the ide From 673bd5550af38c01adc457018b9cdbbd7ae20dac Mon Sep 17 00:00:00 2001 From: mikedeboer Date: Thu, 16 Sep 2010 18:03:28 +0200 Subject: [PATCH 2/3] new keybinding setup implemented --- src/ace/KeyBinding.js | 162 +++++++++--------------- src/ace/conf/keybindings/default_mac.js | 51 ++++++++ src/ace/conf/keybindings/default_win.js | 51 ++++++++ src/ace/lib/lang.js | 17 +++ 4 files changed, 182 insertions(+), 99 deletions(-) create mode 100644 src/ace/conf/keybindings/default_mac.js create mode 100644 src/ace/conf/keybindings/default_win.js diff --git a/src/ace/KeyBinding.js b/src/ace/KeyBinding.js index 276c05be..3779e01c 100644 --- a/src/ace/KeyBinding.js +++ b/src/ace/KeyBinding.js @@ -1,16 +1,20 @@ ace.provide("ace.KeyBinding"); -ace.KeyBinding = function(element, editor) { +ace.KeyBinding = function(element, editor, config) { this.editor = editor; + this.setConfig(config); var keys = this.keys; - var self = this; + var _self = this; ace.addKeyListener(element, function(e) { var key = []; - if (e.ctrlKey || e.metaKey) { + if (e.ctrlKey) { key.push("Control"); } + if (e.metaKey) { + key.push("Meta"); + } if (e.altKey) { key.push("Alt"); } @@ -19,10 +23,10 @@ ace.KeyBinding = function(element, editor) { } key.push(keys[e.keyCode] || String.fromCharCode(e.keyCode)); - var command = self[key.join("-")]; + var command = _self[_self.config.reverse[key.join("-")]]; if (command) { - self.selection = editor.getSelection(); - command.call(self); + _self.selection = editor.getSelection(); + command.call(_self); return ace.stopEvent(e); } }); @@ -48,195 +52,155 @@ ace.KeyBinding = function(element, editor) { 91 : "Meta" }; - this["Control-A"] = function() { + this.setConfig = function(config) { + this.config = config || ace.isMac + ? ace.KeyBinding.default_mac + : ace.KeyBinding.default_win; + }; + + this["selectall"] = function() { this.selection.selectAll(); }; - - this["Control-D"] = function() { + this["removeline"] = function() { this.editor.removeLines(); }; - - this["Control-L"] = function() { + this["gotoline"] = function() { var line = parseInt(prompt("Enter line number:")); if (!isNaN(line)) { this.editor.gotoLine(line); } }; - - this["Control-7"] = function() { + this["togglecomment"] = function() { this.editor.toggleCommentLines(); }; - - this["Control-K"] = function() { + this["findnext"] = function() { this.editor.findNext(); }; - - this["Control-Shift-K"] = function() { + this["findprevious"] = function() { this.editor.findPrevious(); }; - - this["Control-F"] = function() { + this["find"] = function() { var needle = prompt("Find:"); this.editor.find(needle); }; - - this["Control-Z"] = function() { + this["undo"] = function() { this.editor.undo(); }; - - this["Control-Shift=Z"] = function() { + this["redo"] = function() { this.editor.redo(); }; - - this["Control-Y"] = function() { + this["redo"] = function() { this.editor.redo(); }; - - this["Insert"] = function() { + this["overwrite"] = function() { this.editor.toggleOverwrite(); }; - - this["Control-Alt-Up"] = function() { + this["copylinesup"] = function() { this.editor.copyLinesUp(); }; - - this["Alt-Up"] = function() { + this["movelinesup"] = function() { this.editor.moveLinesUp(); }; - - this["Control-Shift-Up"] = function() { + this["selecttostart"] = function() { this.selection.selectFileStart(); }; - - this["Control-Home"] = this["Control-Up"] = function() { + this["gotostart"] = this["Control-Up"] = function() { this.editor.navigateFileStart(); }; - - this["Shift-Up"] = function() { + this["selectup"] = function() { this.selection.selectUp(); }; - - this["Up"] = function() { + this["golineup"] = function() { this.editor.navigateUp(); }; - - this["Control-Alt-Down"] = function() { + this["copylinesdown"] = function() { this.editor.copyLinesDown(); }; - - this["Alt-Down"] = function() { + this["movelinsedown"] = function() { this.editor.moveLinesDown(); }; - - this["Control-Shift-Down"] = function() { + this["selecttoend"] = function() { this.selection.selectFileEnd(); }; - - this["Control-End"] = this["Control-Down"] = function() { + this["gotoend"] = this["Control-Down"] = function() { this.editor.navigateFileEnd(); }; - - this["Shift-Down"] = function() { + this["selectdown"] = function() { this.selection.selectDown(); }; - - this["Down"] = function() { + this["godown"] = function() { this.editor.navigateDown(); }; - - this["Alt-Shift-Left"] = function() { + this["selectwordleft"] = function() { this.selection.selectWordLeft(); }; - - this["Alt-Left"] = function() { + this["gotowordleft"] = function() { this.editor.navigateWordLeft(); }; - - this["Control-Shift-Left"] = function() { + this["selecttolinestart"] = function() { this.selection.selectLineStart(); }; - - this["Control-Left"] = function() { + this["gotolinestart"] = function() { this.editor.navigateLineStart(); }; - - this["Shift-Left"] = function() { + this["selectleft"] = function() { this.selection.selectLeft(); }; - - this["Left"] = function() { + this["gotoleft"] = function() { this.editor.navigateLeft(); }; - - this["Alt-Shift-Right"] = function() { + this["selectwordright"] = function() { this.selection.selectWordRight(); }; - - this["Alt-Right"] = function() { + this["gotowordright"] = function() { this.editor.navigateWordRight(); }; - - this["Control-Shift-Right"] = function() { + this["selecttolineend"] = function() { this.selection.selectLineEnd(); }; - - this["Control-Right"] = function() { + this["gotolineend"] = function() { this.editor.navigateLineEnd(); }; - - this["Shift-Right"] = function() { + this["selectright"] = function() { this.selection.selectRight(); }; - - this["Right"] = function() { + this["gotoright"] = function() { this.editor.navigateRight(); }; - - this["Shift-PageDown"] = function() { + this["selectpagedown"] = function() { this.editor.selectPageDown(); }; - - this["PageDown"] = function() { + this["pagedown"] = function() { this.editor.scrollPageDown(); }; - - this["Shift-PageUp"] = function() { + this["selectpageup"] = function() { this.editor.selectPageUp(); }; - - this["PageUp"] = function() { + this["pageup"] = function() { this.editor.scrollPageUp(); }; - - this["Shift-Home"] = function() { + this["selectlinestart"] = function() { this.selection.selectLineStart(); }; - - this["Home"] = function() { + this["gotolinestart"] = function() { this.editor.navigateLineStart(); }; - - this["Shift-End"] = function() { + this["selectlineend"] = function() { this.selection.selectLineEnd(); }; - - this["End"] = function() { + this["gotolineend"] = function() { this.editor.navigateLineEnd(); }; - - this["Delete"] = function() { + this["del"] = function() { this.editor.removeRight(); }; - - this["Backspace"] = function() { + this["backspace"] = function() { this.editor.removeLeft(); }; - - this["Shift-Tab"] = function() { + this["outdent"] = function() { this.editor.blockOutdent(); }; - - this["Tab"] = function() { + this["indent"] = function() { if (this.selection.isMultiLine()) { this.editor.blockIndent(); } diff --git a/src/ace/conf/keybindings/default_mac.js b/src/ace/conf/keybindings/default_mac.js new file mode 100644 index 00000000..427ee106 --- /dev/null +++ b/src/ace/conf/keybindings/default_mac.js @@ -0,0 +1,51 @@ +ace.provide("ace.KeyBinding.default_mac"); + +ace.KeyBinding.default_mac = { + "selectall": "Meta-A", + "removeline": "Meta-D", + "gotoline": "Meta-L", + "togglecomment": "Meta-7", + "findnext": "Meta-K", + "findprevious": "Meta-Shift-K", + "find": "Meta-F", + "undo": "Meta-Z", + "redo": "Meta-Shift=Z", + "redo": "Meta-Y", + "overwrite": "Insert", + "copylinesup": "Meta-Alt-Up", + "movelinesup": "Alt-Up", + "selecttostart": "Meta-Shift-Up", + "gotostart": "Meta-Home|Meta-Up", + "selectup": "Shift-Up", + "golineup": "Up", + "copylinesdown": "Meta-Alt-Down", + "movelinsedown": "Alt-Down", + "selecttoend": "Meta-Shift-Down", + "gotoend": "Meta-End|Meta-Down", + "selectdown": "Shift-Down", + "godown": "Down", + "selectwordleft": "Alt-Shift-Left", + "gotowordleft": "Alt-Left", + "selecttolinestart": "Meta-Shift-Left", + "gotolinestart": "Meta-Left|Home", + "selectleft": "Shift-Left", + "gotoleft": "Left", + "selectwordright": "Alt-Shift-Right", + "gotowordright": "Alt-Right", + "selecttolineend": "Meta-Shift-Right", + "gotolineend": "Meta-Right|End", + "selectright": "Shift-Right", + "gotoright": "Right", + "selectpagedown": "Shift-PageDown", + "pagedown": "PageDown", + "selectpageup": "Shift-PageUp", + "pageup": "PageUp", + "selectlinestart": "Shift-Home", + "selectlineend": "Shift-End", + "del": "Delete", + "backspace": "Backspace", + "outdent": "Shift-Tab", + "indent": "Tab" +}; + +ace.KeyBinding.default_mac.reverse = ace.objectReverse(ace.KeyBinding.default_mac, "|"); diff --git a/src/ace/conf/keybindings/default_win.js b/src/ace/conf/keybindings/default_win.js new file mode 100644 index 00000000..1111f685 --- /dev/null +++ b/src/ace/conf/keybindings/default_win.js @@ -0,0 +1,51 @@ +ace.provide("ace.KeyBinding.default_win"); + +ace.KeyBinding.default_win = { + "selectall": "Control-A", + "removeline": "Control-D", + "gotoline": "Control-L", + "togglecomment": "Control-7", + "findnext": "Control-K", + "findprevious": "Control-Shift-K", + "find": "Control-F", + "undo": "Control-Z", + "redo": "Control-Shift=Z", + "redo": "Control-Y", + "overwrite": "Insert", + "copylinesup": "Control-Alt-Up", + "movelinesup": "Alt-Up", + "selecttostart": "Control-Shift-Up", + "gotostart": "Control-Home|Control-Up", + "selectup": "Shift-Up", + "golineup": "Up", + "copylinesdown": "Control-Alt-Down", + "movelinsedown": "Alt-Down", + "selecttoend": "Control-Shift-Down", + "gotoend": "Control-End|Control-Down", + "selectdown": "Shift-Down", + "godown": "Down", + "selectwordleft": "Alt-Shift-Left", + "gotowordleft": "Alt-Left", + "selecttolinestart": "Control-Shift-Left", + "gotolinestart": "Control-Left|Home", + "selectleft": "Shift-Left", + "gotoleft": "Left", + "selectwordright": "Alt-Shift-Right", + "gotowordright": "Alt-Right", + "selecttolineend": "Control-Shift-Right", + "gotolineend": "Control-Right|End", + "selectright": "Shift-Right", + "gotoright": "Right", + "selectpagedown": "Shift-PageDown", + "pagedown": "PageDown", + "selectpageup": "Shift-PageUp", + "pageup": "PageUp", + "selectlinestart": "Shift-Home", + "selectlineend": "Shift-End", + "del": "Delete", + "backspace": "Backspace", + "outdent": "Shift-Tab", + "indent": "Tab" +}; + +ace.KeyBinding.default_win.reverse = ace.objectReverse(ace.KeyBinding.default_win, "|"); diff --git a/src/ace/lib/lang.js b/src/ace/lib/lang.js index 73ea7720..72477bfc 100644 --- a/src/ace/lib/lang.js +++ b/src/ace/lib/lang.js @@ -32,6 +32,23 @@ return copy; }; + this.objectReverse = function(obj, keySplit) { + var i, j, l, key, + ret = {}; + for (i in obj) { + key = obj[i]; + if (keySplit && typeof key == "string") { + key = key.split(keySplit); + for (j = 0, l = key.length; j < l; ++j) + ret[key[j]] = i; + } + else { + ret[key] = i; + } + } + return ret; + }; + this.escapeRegExp = function(str) { return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; From e0c20fd06ddc15d6dcfbf3d5183350d1ad306252 Mon Sep 17 00:00:00 2001 From: mikedeboer Date: Thu, 16 Sep 2010 19:04:11 +0200 Subject: [PATCH 3/3] small change to keybinding files --- src/ace/KeyBinding.js | 2 ++ src/ace/conf/keybindings/default_mac.js | 2 -- src/ace/conf/keybindings/default_win.js | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ace/KeyBinding.js b/src/ace/KeyBinding.js index 3779e01c..cbd939c7 100644 --- a/src/ace/KeyBinding.js +++ b/src/ace/KeyBinding.js @@ -56,6 +56,8 @@ ace.KeyBinding = function(element, editor, config) { this.config = config || ace.isMac ? ace.KeyBinding.default_mac : ace.KeyBinding.default_win; + if (typeof this.config.reverse == "undefined") + this.config.reverse = ace.objectReverse(this.config, "|"); }; this["selectall"] = function() { diff --git a/src/ace/conf/keybindings/default_mac.js b/src/ace/conf/keybindings/default_mac.js index 427ee106..6a6e6f7e 100644 --- a/src/ace/conf/keybindings/default_mac.js +++ b/src/ace/conf/keybindings/default_mac.js @@ -47,5 +47,3 @@ ace.KeyBinding.default_mac = { "outdent": "Shift-Tab", "indent": "Tab" }; - -ace.KeyBinding.default_mac.reverse = ace.objectReverse(ace.KeyBinding.default_mac, "|"); diff --git a/src/ace/conf/keybindings/default_win.js b/src/ace/conf/keybindings/default_win.js index 1111f685..78c77a8d 100644 --- a/src/ace/conf/keybindings/default_win.js +++ b/src/ace/conf/keybindings/default_win.js @@ -47,5 +47,3 @@ ace.KeyBinding.default_win = { "outdent": "Shift-Tab", "indent": "Tab" }; - -ace.KeyBinding.default_win.reverse = ace.objectReverse(ace.KeyBinding.default_win, "|");