refactor key bindings
This commit is contained in:
parent
ff9485f617
commit
214eba9761
1 changed files with 202 additions and 187 deletions
|
|
@ -2,180 +2,27 @@ ace.provide("ace.KeyBinding");
|
||||||
|
|
||||||
ace.KeyBinding = function(element, editor) {
|
ace.KeyBinding = function(element, editor) {
|
||||||
|
|
||||||
|
this.editor = editor;
|
||||||
var keys = this.keys;
|
var keys = this.keys;
|
||||||
|
|
||||||
|
var self = this;
|
||||||
ace.addKeyListener(element, function(e) {
|
ace.addKeyListener(element, function(e) {
|
||||||
var key = e.keyCode;
|
var key = [];
|
||||||
var selection = editor.getSelection();
|
if (e.ctrlKey || e.metaKey) {
|
||||||
|
key.push("Control");
|
||||||
switch (key) {
|
|
||||||
case keys.A:
|
|
||||||
if (e.metaKey) {
|
|
||||||
selection.selectAll();
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
}
|
}
|
||||||
break;
|
if (e.altKey) {
|
||||||
|
key.push("Alt");
|
||||||
case keys.D:
|
|
||||||
if (e.metaKey) {
|
|
||||||
editor.removeLines();
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case keys.L:
|
|
||||||
if (e.metaKey) {
|
|
||||||
var line = parseInt(prompt("Enter line number:"));
|
|
||||||
if (!isNaN(line)) {
|
|
||||||
editor.gotoLine(line);
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case keys["7"]:
|
|
||||||
if (e.metaKey) {
|
|
||||||
editor.toggleCommentLines();
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
|
|
||||||
case keys.UP:
|
|
||||||
if (e.altKey && e.metaKey ) {
|
|
||||||
editor.copyLinesUp();
|
|
||||||
}
|
|
||||||
else if (e.altKey) {
|
|
||||||
editor.moveLinesUp();
|
|
||||||
}
|
|
||||||
else if (e.metaKey && e.shiftKey) {
|
|
||||||
selection.selectFileStart();
|
|
||||||
}
|
|
||||||
else if (e.metaKey) {
|
|
||||||
editor.navigateFileStart();
|
|
||||||
}
|
|
||||||
else if (e.shiftKey) {
|
|
||||||
selection.selectUp();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
editor.navigateUp();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.DOWN:
|
|
||||||
if (e.altKey && e.metaKey ) {
|
|
||||||
editor.copyLinesDown();
|
|
||||||
}
|
|
||||||
else if (e.altKey) {
|
|
||||||
editor.moveLinesDown();
|
|
||||||
}
|
|
||||||
else if (e.metaKey && e.shiftKey) {
|
|
||||||
selection.selectFileEnd();
|
|
||||||
}
|
|
||||||
else if (e.metaKey) {
|
|
||||||
editor.navigateFileEnd();
|
|
||||||
}
|
|
||||||
else if (e.shiftKey) {
|
|
||||||
selection.selectDown();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
editor.navigateDown();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.LEFT:
|
|
||||||
if (e.altKey && e.shiftKey) {
|
|
||||||
selection.selectWordLeft();
|
|
||||||
}
|
|
||||||
else if (e.altKey) {
|
|
||||||
editor.navigateWordLeft();
|
|
||||||
}
|
|
||||||
else if (e.metaKey && e.shiftKey) {
|
|
||||||
selection.selectLineStart();
|
|
||||||
}
|
|
||||||
else if (e.metaKey) {
|
|
||||||
editor.navigateLineStart();
|
|
||||||
}
|
|
||||||
else if (e.shiftKey) {
|
|
||||||
selection.selectLeft();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
editor.navigateLeft();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.RIGHT:
|
|
||||||
if (e.altKey && e.shiftKey) {
|
|
||||||
selection.selectWordRight();
|
|
||||||
}
|
|
||||||
else if (e.altKey) {
|
|
||||||
editor.navigateWordRight();
|
|
||||||
}
|
|
||||||
else if (e.metaKey && e.shiftKey) {
|
|
||||||
selection.selectLineEnd();
|
|
||||||
}
|
|
||||||
else if (e.metaKey) {
|
|
||||||
editor.navigateLineEnd();
|
|
||||||
}
|
|
||||||
else if (e.shiftKey) {
|
|
||||||
selection.selectRight();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
editor.navigateRight();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.PAGEDOWN:
|
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
selection.selectPageDown();
|
key.push("Shift");
|
||||||
}
|
}
|
||||||
else {
|
key.push(keys[e.keyCode] || String.fromCharCode(e.keyCode));
|
||||||
editor.scrollPageDown();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.PAGEUP:
|
var command = self[key.join("-")];
|
||||||
if (e.shiftKey) {
|
if (command) {
|
||||||
selection.selectPageUp();
|
self.selection = editor.getSelection();
|
||||||
}
|
command.call(self);
|
||||||
else {
|
|
||||||
editor.scrollPageUp();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.POS1:
|
|
||||||
if (e.shiftKey) {
|
|
||||||
selection.selectLineStart();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
editor.navigateLineStart();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.END:
|
|
||||||
if (e.shiftKey) {
|
|
||||||
selection.selectLineEnd();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
editor.navigateLineEnd();
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.DELETE:
|
|
||||||
editor.removeRight();
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.BACKSPACE:
|
|
||||||
editor.removeLeft();
|
|
||||||
return ace.stopEvent(e);
|
|
||||||
|
|
||||||
case keys.TAB:
|
|
||||||
if (e.shiftKey) {
|
|
||||||
editor.blockOutdent();
|
|
||||||
} else if (selection.isMultiLine()) {
|
|
||||||
editor.blockIndent();
|
|
||||||
} else {
|
|
||||||
editor.onTextInput("\t");
|
|
||||||
}
|
|
||||||
return ace.stopEvent(e);
|
return ace.stopEvent(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -183,20 +30,188 @@ ace.KeyBinding = function(element, editor) {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
this.keys = {
|
this.keys = {
|
||||||
UP : 38,
|
8: "Backspace",
|
||||||
RIGHT : 39,
|
9: "Tab",
|
||||||
DOWN : 40,
|
16: "Shift",
|
||||||
LEFT : 37,
|
17: "Control",
|
||||||
PAGEUP : 33,
|
18: "Alt",
|
||||||
PAGEDOWN : 34,
|
33: "PageUp",
|
||||||
POS1 : 36,
|
34: "PageDown",
|
||||||
END : 35,
|
35: "End",
|
||||||
DELETE : 46,
|
36: "Home",
|
||||||
BACKSPACE : 8,
|
37: "Left",
|
||||||
TAB : 9,
|
38: "Up",
|
||||||
A : 65,
|
39: "Right",
|
||||||
D: 68,
|
40: "Down",
|
||||||
L: 76,
|
46: "Delete",
|
||||||
"7": 55
|
91: "Meta"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this["Control-A"] = function() {
|
||||||
|
this.selection.selectAll();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-D"] = function() {
|
||||||
|
this.editor.removeLines();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-L"] = function() {
|
||||||
|
var line = parseInt(prompt("Enter line number:"));
|
||||||
|
if (!isNaN(line)) {
|
||||||
|
this.editor.gotoLine(line);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-7"] = function() {
|
||||||
|
this.editor.toggleCommentLines();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Alt-Up"] = function() {
|
||||||
|
this.editor.copyLinesUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Alt-Up"] = function() {
|
||||||
|
this.editor.moveLinesUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Shift-Up"] = function() {
|
||||||
|
this.selection.selectFileStart();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Up"] = function() {
|
||||||
|
this.editor.navigateFileStart();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-Up"] = function() {
|
||||||
|
this.selection.selectUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Up"] = function() {
|
||||||
|
this.editor.navigateUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Alt-Down"] = function() {
|
||||||
|
this.editor.copyLinesDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Alt-Down"] = function() {
|
||||||
|
this.editor.moveLinesDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Shift-Down"] = function() {
|
||||||
|
this.selection.selectFileEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Down"] = function() {
|
||||||
|
this.editor.navigateFileEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-Down"] = function() {
|
||||||
|
this.selection.selectDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Down"] = function() {
|
||||||
|
this.editor.navigateDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Alt-Shift-Left"] = function() {
|
||||||
|
this.selection.selectWordLeft();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Alt-Left"] = function() {
|
||||||
|
this.editor.navigateWordLeft();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Shift-Left"] = function() {
|
||||||
|
this.selection.selectLineStart();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Left"] = function() {
|
||||||
|
this.editor.navigateLineStart();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-Left"] = function() {
|
||||||
|
this.selection.selectLeft();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Left"] = function() {
|
||||||
|
this.editor.navigateLeft();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Alt-Shift-Right"] = function() {
|
||||||
|
this.selection.selectWordRight();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Alt-Right"] = function() {
|
||||||
|
this.editor.navigateWordRight();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Shift-Right"] = function() {
|
||||||
|
this.selection.selectLineEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Control-Right"] = function() {
|
||||||
|
this.editor.navigateLineEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-Right"] = function() {
|
||||||
|
this.selection.selectRight();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Right"] = function() {
|
||||||
|
this.editor.navigateRight();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-PageDown"] = function() {
|
||||||
|
this.editor.selectPageDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["PageDown"] = function() {
|
||||||
|
this.editor.scrollPageDown();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-PageUp"] = function() {
|
||||||
|
this.editor.selectPageUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["PageUp"] = function() {
|
||||||
|
this.editor.scrollPageUp();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-Home"] = function() {
|
||||||
|
this.selection.selectLineStart();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Home"] = function() {
|
||||||
|
this.editor.navigateLineStart();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-End"] = function() {
|
||||||
|
this.selection.selectLineEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["End"] = function() {
|
||||||
|
this.editor.navigateLineEnd();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Delete"] = function() {
|
||||||
|
this.editor.removeRight();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Backspace"] = function() {
|
||||||
|
this.editor.removeLeft();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Shift-Tab"] = function() {
|
||||||
|
this.editor.blockOutdent();
|
||||||
|
};
|
||||||
|
|
||||||
|
this["Tab"] = function() {
|
||||||
|
if (this.selection.isMultiLine()) {
|
||||||
|
this.editor.blockIndent();
|
||||||
|
} else {
|
||||||
|
this.editor.onTextInput("\t");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}).call(ace.KeyBinding.prototype);
|
}).call(ace.KeyBinding.prototype);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue