fixes for keybindings

This commit is contained in:
mikedeboer 2010-09-20 12:22:12 +02:00
commit d5d5e81561
3 changed files with 24 additions and 24 deletions

View file

@ -15,8 +15,8 @@ var Editor = function(renderer, doc) {
this.container = container;
this.renderer = renderer;
this.textInput = new TextInput(container, this);
new KeyBinding(container, this);
this.textInput = new TextInput(container, this);
this.keyBinding = new KeyBinding(container, this);
var self = this;
ace.addListener(container, "mousedown", function(e) {
setTimeout(function() {self.focus();});

View file

@ -11,7 +11,7 @@ var KeyBinding = function(element, editor, config) {
ace.addKeyListener(element, function(e) {
var key = [];
if (e.ctrlKey) {
key.push("Control");
key.push("Ctrl");
}
if (e.metaKey) {
key.push("Meta");
@ -38,7 +38,7 @@ var KeyBinding = function(element, editor, config) {
8 : "Backspace",
9 : "Tab",
16 : "Shift",
17 : "Control",
17 : "Ctrl",
18 : "Alt",
33 : "PageUp",
34 : "PageDown",
@ -53,12 +53,29 @@ var KeyBinding = function(element, editor, config) {
91 : "Meta"
};
function objectReverse(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].replace(/Command/i, "Meta").replace(/Option/i, "Alt")] = i;
}
else {
ret[key.replace(/Command/i, "Meta").replace(/Option/i, "Alt")] = i;
}
}
return ret;
}
this.setConfig = function(config) {
this.config = config || ace.isMac
this.config = config || (ace.isMac
? default_mac
: default_win;
: default_win);
if (typeof this.config.reverse == "undefined")
this.config.reverse = ace.objectReverse(this.config, "|");
this.config.reverse = objectReverse(this.config, "|");
};
this["selectall"] = function() {

View file

@ -43,23 +43,6 @@ require.def("ace/lib/lang", function() {
};
lang.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');
};