filter out all mouse events from keys. see slap-editor/slap-editor#74.

This commit is contained in:
Christopher Jeffrey 2015-02-13 19:24:26 -08:00
parent 03cdfbb39c
commit a335257505
2 changed files with 21 additions and 11 deletions

View File

@ -117,7 +117,7 @@ function emitKey(stream, s) {
}
}
if (~s.indexOf('\x1b[M')) {
if (isMouse(s)) {
return;
}
@ -314,3 +314,13 @@ function emitKey(stream, s) {
// }
}
}
function isMouse(s) {
return /\x1b\[M/.test(s)
|| /\x1b\[M([\x00\u0020-\uffff]{3})/.test(s)
|| /\x1b\[(\d+;\d+;\d+)M/.test(s)
|| /\x1b\[<(\d+;\d+;\d+)([mM])/.test(s)
|| /\x1b\[<(\d+;\d+;\d+;\d+)&w/.test(s)
|| /\x1b\[24([0135])~\[(\d+),(\d+)\]\r/.test(s)
|| /\x1b\[(O|I)/.test(s);
}

View File

@ -515,7 +515,7 @@ Program.prototype._bindMouse = function(s, buf) {
key.action = 'mousemove';
}
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
return;
@ -585,7 +585,7 @@ Program.prototype._bindMouse = function(s, buf) {
key.action = 'mousemove';
}
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
return;
@ -644,7 +644,7 @@ Program.prototype._bindMouse = function(s, buf) {
key.action = 'mousemove';
}
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
return;
@ -680,7 +680,7 @@ Program.prototype._bindMouse = function(s, buf) {
: b === 6 ? 'right'
: 'unknown';
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
return;
@ -709,7 +709,7 @@ Program.prototype._bindMouse = function(s, buf) {
: b === 5 ? 'right'
: 'unknown';
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
return;
@ -768,7 +768,7 @@ Program.prototype.enableGpm = function() {
ctrl: self.gpm.hasCtrlKey(modifier)
};
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
});
@ -788,7 +788,7 @@ Program.prototype.enableGpm = function() {
ctrl: self.gpm.hasCtrlKey(modifier)
};
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
});
@ -808,7 +808,7 @@ Program.prototype.enableGpm = function() {
ctrl: self.gpm.hasCtrlKey(modifier)
};
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
});
@ -828,7 +828,7 @@ Program.prototype.enableGpm = function() {
ctrl: self.gpm.hasCtrlKey(modifier)
};
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
});
@ -846,7 +846,7 @@ Program.prototype.enableGpm = function() {
ctrl: self.gpm.hasCtrlKey(modifier)
};
self.emit('keypress', null, key);
// self.emit('keypress', null, key);
self.emit('mouse', key);
});
};