Key callback helper

This commit is contained in:
2014-11-17 00:46:41 +01:00
parent 169b8397dc
commit dd227d2863
2 changed files with 31 additions and 19 deletions

View File

@@ -13,6 +13,7 @@ function Buffer (client, buffId, path) {
this.title = undefined;
var typeNum = 0; //WARNING : check if this should be unique to a buffer
var serNum = 0; //WARNING : check if this should be unique to a buffer
var keysCallback = {};
/* COMMANDS */
@@ -182,12 +183,21 @@ function Buffer (client, buffId, path) {
client.callFunction("remove", buffId, Types.position(off), length, callback);
};
var keysCallback = {};
//Register a key callback that will only be called on this buffer
this.registerKey = function (key, callback) {
client.specialKeys(key);
client.sendCommand("specialKeys", 0, Types.string(key));
Object.defineProperty(keysCallback, key, { value: callback, configurable: true});
};
this.handleKey = function (key, line, col) {
if (keysCallback.hasOwnProperty(arguments[2])){
keysCallback[arguments[2]].call(null, line, col);
return true;
}
else {
return false;
}
};
}
util.inherits(Buffer, EventEmitter);