Match menus to keys under new system
Tells the menu component to use the same keyboard handler as the keys.js for the purpose of showing menu hints. Cleans up rebinding code significantly. Fixes #350
This commit is contained in:
parent
398e42a4f1
commit
83416cd0bf
4 changed files with 35 additions and 19 deletions
|
@ -51,7 +51,7 @@
|
|||
}
|
||||
|
||||
&.parent::after {
|
||||
content: "►";
|
||||
content: "...";
|
||||
font-family: serif;
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
|
|
|
@ -58,19 +58,15 @@ define([
|
|||
var bindings = normalizeKeys(Settings.get("keys"));
|
||||
var ckb = handler.commandKeyBinding;
|
||||
for (var k in bindings) {
|
||||
//unbind keys that we take over from Ace
|
||||
if (ckb[k]) {
|
||||
delete ckb[k];
|
||||
}
|
||||
var action = bindings[k];
|
||||
if (!action) continue;
|
||||
var parsed = handler.parseKeys(k);
|
||||
var existing = handler.findKeyCommand(parsed.hashId, parsed.key);
|
||||
var aceCommand = action.command == "ace:command" ? action.argument : action.ace;
|
||||
if (!aceCommand && ckb[parsed.hashId] && ckb[parsed.hashId][parsed.key]) {
|
||||
//old-style Ace hashed CommandKeyBinding
|
||||
delete ckb[parsed.hashId][parsed.key];
|
||||
} else if (!aceCommand && ckb[k]) {
|
||||
//handle new style CommandKeyBinding
|
||||
delete ckb[k];
|
||||
} else {
|
||||
handler.bindKey(k, aceCommand);
|
||||
//if a key is defined with an Ace command, bind it via their handler
|
||||
if (action.ace || action.command == "ace:command") {
|
||||
handler.bindKey(k, action.ace || action.argument);
|
||||
}
|
||||
}
|
||||
handler.commandKeyBinding = ckb;
|
||||
|
@ -104,6 +100,7 @@ define([
|
|||
if (combo in keyConfig && keyConfig[combo]) {
|
||||
e.preventDefault();
|
||||
var action = keyConfig[combo];
|
||||
if (!action) return;
|
||||
if (typeof action == "string") {
|
||||
action = {
|
||||
command: action
|
||||
|
|
|
@ -59,11 +59,30 @@ define([
|
|||
}
|
||||
return fragment;
|
||||
};
|
||||
|
||||
var capitalizeAceKeys = function(s) {
|
||||
return s.replace(/(^\w|\b\w)/g, function(l) { return l.toUpperCase() });
|
||||
};
|
||||
|
||||
var testAceBinding = function(key, binding, command) {
|
||||
if (typeof binding == "string" && binding == command) {
|
||||
return key;
|
||||
} else if (binding instanceof Array) {
|
||||
for (var i = 0; i < binding.length; i++) {
|
||||
var b = testAceBinding(key, binding[i], command);
|
||||
if (b) return b;
|
||||
}
|
||||
} else if (binding.name == command && binding.bindKey[platform]) {
|
||||
return binding.bindKey[platform].split("|").shift();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// We load match commands to the key config, so they're always current
|
||||
var findKeyCombo = function(command, arg) {
|
||||
var keys = Settings.get("keys");
|
||||
var aceCommands = editor.commands.commands;
|
||||
var handler = editor.keyBinding.getKeyboardHandler();
|
||||
var ckb = handler.commandKeyBinding;
|
||||
//check key config
|
||||
for (var key in keys) {
|
||||
var action = keys[key];
|
||||
|
@ -83,10 +102,10 @@ define([
|
|||
return key;
|
||||
}
|
||||
}
|
||||
for (var cmd in aceCommands) {
|
||||
if (cmd == command && aceCommands[cmd].bindKey[platform]) {
|
||||
return aceCommands[cmd].bindKey[platform].split("|").shift();
|
||||
}
|
||||
//fall back to Ace defaults
|
||||
if (command) for (var k in ckb) {
|
||||
var binding = testAceBinding(k, ckb[k], command);
|
||||
if (binding) return capitalizeAceKeys(binding);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Caret</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="css/caret.css" id="theme">
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" type="text/css" href="css/caret.css" id="theme" charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
Loading…
Reference in a new issue