change screen keypress behavior.

This commit is contained in:
Christopher Jeffrey 2013-06-25 17:31:13 -05:00
parent 77593efd05
commit c265194182
3 changed files with 38 additions and 7 deletions

View File

@ -326,6 +326,7 @@ A box with scrollable content.
- inherits all from Box.
- **scroll** - received when the element is scrolled.
- **resetScroll** - reset scroll offset to zero.
##### Methods:

View File

@ -125,7 +125,7 @@ Program.prototype.listen = function() {
if (self.listeners('SIGINT').length) {
self.emit('SIGINT');
}
return;
// return;
}
if (key.name === 'undefined' && key.code === '[M') {
// A mouse sequence. The readline module doesn't understand these.

View File

@ -165,6 +165,18 @@ Node.prototype.emitDescendants = function() {
})(this);
};
Node.prototype.gon = function(type, callback) {
var self = this
, events = this._events || {}
, listeners = (events[type] || []).slice();
return this.on(type, function fn(ch, key) {
if (callback(ch, key) === true) {
self._events[type] = listeners;
}
});
};
/**
* Screen
*/
@ -371,13 +383,24 @@ Screen.prototype._listenKeys = function(el) {
this.program.on('keypress', function(ch, key) {
if (self.lockKeys) return;
if (~self.input.indexOf(self.focused)) {
self.focused.emit('keypress', ch, key);
}
var focused = self.focused;
if (!self.grabKeys) {
self.emit('keypress', ch, key);
}
if (~self.input.indexOf(focused)) {
focused.emit('keypress', ch, key);
}
});
//this.program.on('keypress', function(ch, key) {
// if (self.lockKeys) return;
// if (~self.input.indexOf(self.focused)) {
// self.focused.emit('keypress', ch, key);
// }
// if (!self.grabKeys) {
// self.emit('keypress', ch, key);
// }
//});
};
Screen.prototype.__defineGetter__('cols', function() {
@ -1705,6 +1728,11 @@ ScrollableBox.prototype.scroll = function(offset) {
this.emit('scroll');
};
ScrollableBox.prototype.resetScroll = function() {
this.childOffset = 0;
this.childBase = 0;
};
/**
* List
*/
@ -1767,7 +1795,7 @@ function List(options) {
self.screen.render();
return;
}
if (key.name === 'enter' || (options.vi && key.name === 'j')) {
if (key.name === 'enter' || (options.vi && key.name === 'l')) {
self.emit('action', self.items[self.selected], self.selected);
self.emit('select', self.items[self.selected], self.selected);
return;
@ -2093,8 +2121,11 @@ function Textbox(options) {
if (!(this instanceof Textbox)) {
return new Textbox(options);
}
Input.call(this, options);
this.screen._listenKeys(this);
this.value = options.value || '';
this.secret = options.secret;
this.censor = options.censor;
@ -2544,13 +2575,12 @@ function sp(line, width, align) {
return line;
}
// TODO: Add text padding.
function wrapContent(content, width, tags, state) {
var lines = content.split('\n')
, out = [];
if (!content) {
out.width = width;
out.content = content || '';
out.push(content || '');
return out;
}