[vim] pass unhandled keys to the browser

This commit is contained in:
nightwing 2012-11-29 23:19:16 +04:00
commit 59f5e7ffca
3 changed files with 23 additions and 20 deletions

View file

@ -90,30 +90,28 @@ var KeyBinding = function(editor) {
this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) { this.$callKeyboardHandlers = function (hashId, keyString, keyCode, e) {
var toExecute; var toExecute;
var success = false;
var commands = this.$editor.commands;
for (var i = this.$handlers.length; i--;) { for (var i = this.$handlers.length; i--;) {
toExecute = this.$handlers[i].handleKeyboard( 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)
continue;
// allow keyboardHandler to consume keys
if (toExecute.command == "null") {
success = toExecute.passEvent != true;
} else {
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
}
// do not stop input events to not break repeating
if (success && e && hashId != -1)
event.stopEvent(e);
if (success)
break; break;
} }
if (!toExecute || !toExecute.command)
return false;
var success = false;
var commands = this.$editor.commands;
// allow keyboardHandler to consume keys
if (toExecute.command != "null")
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e);
else
success = toExecute.passEvent != true;
// do not stop input events to not break repeating
if (success && e && hashId != -1)
event.stopEvent(e);
return success; return success;
}; };

View file

@ -101,7 +101,9 @@ exports.handler = {
return startCommands[key]; return startCommands[key];
return { return {
command: { command: {
exec: function(editor) {cmds.inputBuffer.push(editor, key);} exec: function(editor) {
return cmds.inputBuffer.push(editor, key);
}
} }
}; };
} // if no modifier || shift: wait for input. } // if no modifier || shift: wait for input.

View file

@ -305,6 +305,7 @@ var inputBuffer = exports.inputBuffer = {
lastInsertCommands: [], lastInsertCommands: [],
push: function(editor, ch, keyId) { push: function(editor, ch, keyId) {
var isKeyHandled = true;
this.idle = false; this.idle = false;
var wObj = this.waitingForParam; var wObj = this.waitingForParam;
if (wObj) { if (wObj) {
@ -369,6 +370,7 @@ var inputBuffer = exports.inputBuffer = {
this.exec(editor, { operator: this.operator }, ch); this.exec(editor, { operator: this.operator }, ch);
} }
else { else {
isKeyHandled = ch.length == 1;
this.reset(); this.reset();
} }
@ -379,9 +381,10 @@ var inputBuffer = exports.inputBuffer = {
} else if (this.status) { } else if (this.status) {
this.status = ""; this.status = "";
} else { } else {
return; return isKeyHandled;
} }
editor._emit("changeStatus"); editor._emit("changeStatus");
return isKeyHandled;
}, },
waitForParam: function(cmd) { waitForParam: function(cmd) {