Merge pull request #894 from ajaxorg/keys
better handling of keys without modifiers
This commit is contained in:
commit
4fc6114be9
6 changed files with 79 additions and 66 deletions
|
|
@ -68,20 +68,20 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: mac hotkeys": function() {
|
"test: mac hotkeys": function() {
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "l");
|
||||||
assert.equal(command, this.command);
|
assert.equal(command, this.command);
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "L");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "l");
|
||||||
assert.equal(command, undefined);
|
assert.equal(command, undefined);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: win hotkeys": function() {
|
"test: win hotkeys": function() {
|
||||||
var cm = new CommandManager("win", [this.command]);
|
var cm = new CommandManager("win", [this.command]);
|
||||||
|
|
||||||
var command = cm.findKeyCommand(keys.KEY_MODS.command, "L");
|
var command = cm.findKeyCommand(keys.KEY_MODS.command, "l");
|
||||||
assert.equal(command, undefined);
|
assert.equal(command, undefined);
|
||||||
|
|
||||||
var command = cm.findKeyCommand(keys.KEY_MODS.ctrl, "L");
|
var command = cm.findKeyCommand(keys.KEY_MODS.ctrl, "l");
|
||||||
assert.equal(command, this.command);
|
assert.equal(command, this.command);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ module.exports = {
|
||||||
this.cm.exec("gotoline");
|
this.cm.exec("gotoline");
|
||||||
assert.ok(!this.command.called);
|
assert.ok(!this.command.called);
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "l");
|
||||||
assert.equal(command, null);
|
assert.equal(command, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ module.exports = {
|
||||||
this.cm.exec("gotoline");
|
this.cm.exec("gotoline");
|
||||||
assert.ok(!this.command.called);
|
assert.ok(!this.command.called);
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "L");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "l");
|
||||||
assert.equal(command, null);
|
assert.equal(command, null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ module.exports = {
|
||||||
assert.ok(command.called);
|
assert.ok(command.called);
|
||||||
assert.ok(!this.command.called);
|
assert.ok(!this.command.called);
|
||||||
|
|
||||||
assert.equal(this.cm.findKeyCommand(keys.KEY_MODS.command, "L"), command);
|
assert.equal(this.cm.findKeyCommand(keys.KEY_MODS.command, "l"), command);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: adding commands and recording a macro": function() {
|
"test: adding commands and recording a macro": function() {
|
||||||
|
|
@ -161,33 +161,41 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: bindkeys": function() {
|
"test: bindkeys": function() {
|
||||||
var called = "";
|
|
||||||
this.cm.addCommands({
|
|
||||||
cm1: function(editor, arg) {
|
|
||||||
called += "1" + (arg || "");
|
|
||||||
},
|
|
||||||
cm2: function(editor) {
|
|
||||||
called += "2";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.cm.bindKeys({
|
this.cm.bindKeys({
|
||||||
"Ctrl-L|Command-C": "cm1",
|
"Ctrl-L|Command-C": "cm1",
|
||||||
"Ctrl-R": "cm2"
|
"Ctrl-R": "cm2"
|
||||||
});
|
});
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "C");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.command, "c");
|
||||||
assert.equal(command, "cm1");
|
assert.equal(command, "cm1");
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "R");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "r");
|
||||||
assert.equal(command, "cm2");
|
assert.equal(command, "cm2");
|
||||||
|
|
||||||
this.cm.bindKeys({
|
this.cm.bindKeys({
|
||||||
"Ctrl-R": null
|
"Ctrl-R": null
|
||||||
});
|
});
|
||||||
|
|
||||||
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "R");
|
var command = this.cm.findKeyCommand(keys.KEY_MODS.ctrl, "r");
|
||||||
assert.equal(command, null);
|
assert.equal(command, null);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: binding keys without modifiers": function() {
|
||||||
|
this.cm.bindKeys({
|
||||||
|
"R": "cm1",
|
||||||
|
"Shift-r": "cm2",
|
||||||
|
"Return": "cm4",
|
||||||
|
"Enter": "cm3"
|
||||||
|
});
|
||||||
|
|
||||||
|
var command = this.cm.findKeyCommand(-1, "r");
|
||||||
|
assert.equal(command, "cm1");
|
||||||
|
|
||||||
|
var command = this.cm.findKeyCommand(-1, "R");
|
||||||
|
assert.equal(command, "cm2");
|
||||||
|
|
||||||
|
var command = this.cm.findKeyCommand(0, "return");
|
||||||
|
assert.equal(command, "cm3");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,33 +129,34 @@ function HashHandler(config, platform) {
|
||||||
var key = typeof binding == "string" ? binding: binding[this.platform];
|
var key = typeof binding == "string" ? binding: binding[this.platform];
|
||||||
this.bindKey(key, command);
|
this.bindKey(key, command);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// accepts keys in the form ctrl+Enter or ctrl-Enter
|
||||||
|
// keys without modifiers or shift only
|
||||||
this.parseKeys = function(keys) {
|
this.parseKeys = function(keys) {
|
||||||
var key;
|
var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x});
|
||||||
|
var key = parts.pop();
|
||||||
|
|
||||||
|
var keyCode = keyUtil[key];
|
||||||
|
if (keyUtil.FUNCTION_KEYS[keyCode])
|
||||||
|
key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase();
|
||||||
|
else if (!parts.length)
|
||||||
|
return {key: key, hashId: -1};
|
||||||
|
else if (parts.length == 1 && parts[0] == "shift")
|
||||||
|
return {key: key.toUpperCase(), hashId: -1};
|
||||||
|
|
||||||
var hashId = 0;
|
var hashId = 0;
|
||||||
var parts = keys.toLowerCase().trim().split(/\s*\-\s*/);
|
for (var i = parts.length; i--;) {
|
||||||
|
var modifier = keyUtil.KEY_MODS[parts[i]];
|
||||||
for (var i = 0, l = parts.length; i < l; i++) {
|
if (modifier == null)
|
||||||
if (keyUtil.KEY_MODS[parts[i]])
|
throw "invalid modifier " + parts[i] + " in " + keys;
|
||||||
hashId = hashId | keyUtil.KEY_MODS[parts[i]];
|
hashId |= modifier;
|
||||||
else
|
|
||||||
key = parts[i] || "-"; //when empty, the splitSafe removed a '-'
|
|
||||||
}
|
}
|
||||||
|
return {key: key, hashId: hashId};
|
||||||
if (parts[0] == "text" && parts.length == 2) {
|
|
||||||
hashId = -1;
|
|
||||||
key = parts[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
key: key,
|
|
||||||
hashId: hashId
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.findKeyCommand = function findKeyCommand(hashId, keyString) {
|
this.findKeyCommand = function findKeyCommand(hashId, keyString) {
|
||||||
var ckbr = this.commmandKeyBinding;
|
var ckbr = this.commmandKeyBinding;
|
||||||
return ckbr[hashId] && ckbr[hashId][keyString.toLowerCase()];
|
return ckbr[hashId] && ckbr[hashId][keyString];
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handleKeyboard = function(data, hashId, keyString, keyCode) {
|
this.handleKeyboard = function(data, hashId, keyString, keyCode) {
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ var Keys = (function() {
|
||||||
|
|
||||||
// A reverse map of FUNCTION_KEYS
|
// A reverse map of FUNCTION_KEYS
|
||||||
for (var i in ret.FUNCTION_KEYS) {
|
for (var i in ret.FUNCTION_KEYS) {
|
||||||
var name = ret.FUNCTION_KEYS[i].toUpperCase();
|
var name = ret.FUNCTION_KEYS[i].toLowerCase();
|
||||||
ret[name] = parseInt(i, 10);
|
ret[name] = parseInt(i, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +118,11 @@ var Keys = (function() {
|
||||||
oop.mixin(ret, ret.PRINTABLE_KEYS);
|
oop.mixin(ret, ret.PRINTABLE_KEYS);
|
||||||
oop.mixin(ret, ret.FUNCTION_KEYS);
|
oop.mixin(ret, ret.FUNCTION_KEYS);
|
||||||
|
|
||||||
|
// aliases
|
||||||
|
ret.enter = ret["return"];
|
||||||
|
ret.escape = ret.esc;
|
||||||
|
ret.del = ret["delete"];
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
})();
|
})();
|
||||||
oop.mixin(exports, Keys);
|
oop.mixin(exports, Keys);
|
||||||
|
|
|
||||||
|
|
@ -19,37 +19,32 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
|
||||||
var tokens = tokenizedLine.tokens;
|
var tokens = tokenizedLine.tokens;
|
||||||
|
|
||||||
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
if (tokens.length && tokens[tokens.length-1].type == "comment") {
|
||||||
return indent;
|
return indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == "start") {
|
if (state == "start") {
|
||||||
var match = line.match(/^.*[\{\(\[]\s*$/);
|
var match = line.match(/^.*[\{\(\[]\s*$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
indent += tab;
|
indent += tab;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return indent;
|
return indent;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.checkOutdent = function(state, line, input) {
|
this.checkOutdent = function(state, line, input) {
|
||||||
return this.$outdent.checkOutdent(line, input);
|
return this.$outdent.checkOutdent(line, input);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.autoOutdent = function(state, doc, row) {
|
this.autoOutdent = function(state, doc, row) {
|
||||||
this.$outdent.autoOutdent(doc, row);
|
this.$outdent.autoOutdent(doc, row);
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
this.createWorker = function(session) {
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ define(function(require, exports, module) {
|
||||||
var oop = require("../lib/oop");
|
var oop = require("../lib/oop");
|
||||||
var TextMode = require("./text").Mode;
|
var TextMode = require("./text").Mode;
|
||||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||||
var TclHighlightRules = require("./tcl_highlight_rules").TclHighlightRules;
|
var TclHighlightRules = require("./tcl_highlight_rules").TclHighlightRules;
|
||||||
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||||
var Range = require("../range").Range;
|
var Range = require("../range").Range;
|
||||||
|
|
@ -49,6 +50,7 @@ var Range = require("../range").Range;
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new TclHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new TclHighlightRules().getRules());
|
||||||
this.$outdent = new MatchingBraceOutdent();
|
this.$outdent = new MatchingBraceOutdent();
|
||||||
|
this.foldingRules = new CStyleFoldMode();
|
||||||
};
|
};
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,12 @@ var TextMode = require("./text").Mode;
|
||||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
var YamlHighlightRules = require("./yaml_highlight_rules").YamlHighlightRules;
|
var YamlHighlightRules = require("./yaml_highlight_rules").YamlHighlightRules;
|
||||||
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
|
||||||
|
var FoldMode = require("./folding/coffee").FoldMode;
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.$tokenizer = new Tokenizer(new YamlHighlightRules().getRules());
|
this.$tokenizer = new Tokenizer(new YamlHighlightRules().getRules());
|
||||||
this.$outdent = new MatchingBraceOutdent();
|
this.$outdent = new MatchingBraceOutdent();
|
||||||
|
this.foldingRules = new FoldMode();
|
||||||
};
|
};
|
||||||
oop.inherits(Mode, TextMode);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue