We are now passing along the original Keyboard event for keybindings
The original keyboard event is now passed on, and `$composeBuffer` is returning with an extra property `keyIdentifier`, which contains the Unicode id of the pressed keybinding.
This commit is contained in:
parent
cd271f1a8b
commit
d3013ad835
2 changed files with 22 additions and 15 deletions
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
|
var useragent = require("../lib/useragent");
|
||||||
var keyUtil = require("../lib/keys");
|
var keyUtil = require("../lib/keys");
|
||||||
var event = require("../lib/event");
|
var event = require("../lib/event");
|
||||||
require("../commands/default_commands");
|
require("../commands/default_commands");
|
||||||
|
|
@ -75,9 +76,8 @@ var KeyBinding = function(editor) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
|
this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
|
||||||
var toExecute;
|
|
||||||
for (var i = this.$handlers.length; i--;) {
|
for (var i = this.$handlers.length; i--;) {
|
||||||
toExecute = this.$handlers[i].handleKeyboard(
|
var toExecute = this.$handlers[i].handleKeyboard(
|
||||||
this.$data, hashId, keyString, keyCode, e
|
this.$data, hashId, keyString, keyCode, e
|
||||||
);
|
);
|
||||||
if (toExecute && toExecute.command)
|
if (toExecute && toExecute.command)
|
||||||
|
|
@ -97,13 +97,13 @@ var KeyBinding = function(editor) {
|
||||||
if (success && e)
|
if (success && e)
|
||||||
event.stopEvent(e);
|
event.stopEvent(e);
|
||||||
|
|
||||||
return success;
|
return success
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handleKeyboard = function(data, hashId, keyString) {
|
this.handleKeyboard = function(data, hashId, keyString) {
|
||||||
return {
|
return {
|
||||||
command: this.$editor.commands.findKeyCommand(hashId, keyString)
|
command: this.$editor.commands.findKeyCommand(hashId, keyString)
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onCommandKey = function(e, hashId, keyCode) {
|
this.onCommandKey = function(e, hashId, keyCode) {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ StateHandler.prototype = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
$composeBuffer: function(data, hashId, key) {
|
$composeBuffer: function(data, hashId, key, e) {
|
||||||
// Initialize the data object.
|
// Initialize the data object.
|
||||||
if (data.state == null || data.buffer == null) {
|
if (data.state == null || data.buffer == null) {
|
||||||
data.state = "start";
|
data.state = "start";
|
||||||
|
|
@ -102,17 +102,23 @@ StateHandler.prototype = {
|
||||||
data.buffer = bufferToUse;
|
data.buffer = bufferToUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
var bufferObj = {
|
||||||
bufferToUse: bufferToUse,
|
bufferToUse: bufferToUse,
|
||||||
symbolicName: symbolicName
|
symbolicName: symbolicName,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (e) {
|
||||||
|
bufferObj.keyIdentifier = e.keyIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
return bufferObj;
|
||||||
},
|
},
|
||||||
|
|
||||||
$find: function(data, buffer, symbolicName, hashId, key) {
|
$find: function(data, buffer, symbolicName, hashId, key, keyIdentifier) {
|
||||||
// Holds the command to execute and the args if a command matched.
|
// Holds the command to execute and the args if a command matched.
|
||||||
var result = {};
|
var result = {};
|
||||||
|
|
||||||
// Loop over all the bindings of the keymapp until a match is found.
|
// Loop over all the bindings of the keymap until a match is found.
|
||||||
this.keymapping[data.state].some(function(binding) {
|
this.keymapping[data.state].some(function(binding) {
|
||||||
var match;
|
var match;
|
||||||
|
|
||||||
|
|
@ -127,7 +133,7 @@ StateHandler.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the match function matches.
|
// Check if the match function matches.
|
||||||
if (binding.match && !binding.match(buffer, hashId, key, symbolicName)) {
|
if (binding.match && !binding.match(buffer, hashId, key, symbolicName, keyIdentifier)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,20 +200,21 @@ StateHandler.prototype = {
|
||||||
/**
|
/**
|
||||||
* This function is called by keyBinding.
|
* This function is called by keyBinding.
|
||||||
*/
|
*/
|
||||||
handleKeyboard: function(data, hashId, key) {
|
handleKeyboard: function(data, hashId, key, keyCode, e) {
|
||||||
// If we pressed any command key but no other key, then ignore the input.
|
// If we pressed any command key but no other key, then ignore the input.
|
||||||
// Otherwise "shift-" is added to the buffer, and later on "shift-g"
|
// Otherwise "shift-" is added to the buffer, and later on "shift-g"
|
||||||
// which results in "shift-shift-g" which doesn't make senese.
|
// which results in "shift-shift-g" which doesn't make sense.
|
||||||
if (hashId != 0 && (key == "" || key == String.fromCharCode(0))) {
|
if (hashId != 0 && (key == "" || key == String.fromCharCode(0))) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the current value of the keyboard input buffer.
|
// Compute the current value of the keyboard input buffer.
|
||||||
var r = this.$composeBuffer(data, hashId, key);
|
var r = this.$composeBuffer(data, hashId, key, e);
|
||||||
var buffer = r.bufferToUse;
|
var buffer = r.bufferToUse;
|
||||||
var symbolicName = r.symbolicName;
|
var symbolicName = r.symbolicName;
|
||||||
|
var keyId = r.keyIdentifier;
|
||||||
|
|
||||||
r = this.$find(data, buffer, symbolicName, hashId, key);
|
r = this.$find(data, buffer, symbolicName, hashId, key, keyId);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log("KeyboardStateMapper#match", buffer, symbolicName, r);
|
console.log("KeyboardStateMapper#match", buffer, symbolicName, r);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue