hide focus. public index prop. select item on dbl click.

This commit is contained in:
Christopher Jeffrey 2013-07-11 22:52:46 -05:00
parent 3eb382e8f1
commit 2356d30394
2 changed files with 12 additions and 10 deletions

View File

@ -137,6 +137,7 @@ The base node which everything inherits from.
- **screen** - parent screen.
- **children** - array of node's children.
- **data, _, $** - an object for any miscellanous user data.
- **index** - render index (document order index) of the last render call.
##### Events:

View File

@ -29,7 +29,7 @@ function Node(options) {
this.children = [];
this.$ = this._ = this.data = {};
this.uid = Node.uid++;
this._index = -1;
this.index = -1;
if (this.parent) {
this.parent.append(this);
@ -237,13 +237,13 @@ function Screen(options) {
bottom: this.bottom = this.rbottom = 0
};
// this.focused;
this.hover = null;
this.history = [];
this.clickable = [];
this.input = [];
this.grabKeys = false;
this.lockKeys = false;
this.focused;
this._ci = -1;
@ -348,7 +348,7 @@ Screen.prototype._listenMouse = function(el) {
el.emit('click', data);
self.emit('element click', el, data);
} else if (data.action === 'mousemove') {
if (self.hover && el._index > self.hover._index) {
if (self.hover && el.index > self.hover.index) {
set = false;
}
if (self.hover !== el && !set) {
@ -478,7 +478,7 @@ Screen.prototype.render = function() {
// this.screen.clearRegion(0, this.cols, 0, this.rows);
this._ci = 0;
this.children.forEach(function(el) {
el._index = self._ci++;
el.index = self._ci++;
el.render();
});
this._ci = -1;
@ -1086,10 +1086,8 @@ Element.prototype.hide = function() {
this.hidden = true;
this.clearPos();
this.emit('hide');
if (this.screen.focused === this && this.history[this.history.length-2]) {
this.history[this.history.length-2].focus();
}
var below = this.screen.history[this.screen.history.length-2];
if (below && this.screen.focused === this) below.focus();
};
Element.prototype.show = function() {
@ -1104,7 +1102,6 @@ Element.prototype.toggle = function() {
};
Element.prototype.focus = function() {
// if (this.screen.grabKeys || this.screen.lockKeys) return;
var old = this.screen.focused;
this.screen.focused = this;
old.emit('blur', this);
@ -1779,7 +1776,7 @@ outer:
this.children.forEach(function(el) {
if (el.screen._ci !== -1) {
el._index = el.screen._ci++;
el.index = el.screen._ci++;
}
el.render();
});
@ -2108,6 +2105,10 @@ List.prototype.add = function(item) {
if (this.mouse) {
item.on('click', function(data) {
if (self.items[self.selected] === item) {
self.emit('select', item, self.selected);
return;
}
self.select(item);
self.screen.render();
});