Key callback helper
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user