diff --git a/lib/widget.js b/lib/widget.js index 3692daf..de66ebb 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -372,8 +372,7 @@ Screen.prototype._listenMouse = function(el) { el.emit('click', data); self.emit('element click', el, data); } else if (data.action === 'mousemove') { - //if (el.hasAncestor(self.hover)) { - if (self.hover && self.getIndex(el) > self.getIndex(self.hover)) { + if (self.hover && el._index > self.hover._index) { set = false; } if (self.hover !== el && !set) { @@ -809,49 +808,6 @@ Screen.prototype.fillRegion = function(attr, ch, xi, xl, yi, yl) { } }; -// Get the element's index in order of rendering. -Screen.prototype.getIndex = function(target) { - return target._index; -}; - -// Get the element's index in order of rendering. -Screen.prototype.getIndex_ = function(target) { - var pos = target._lastPos || {} - , hash; - - //hash = pos.xi + ':' + pos.xl + ':' - // + pos.yi + ':' + pos.yl + ':' - // + target.parent.uid + ':' - // + (target.parent ? target.parent.children.indexOf(target) : ''); - - if (!target.parent) return -1; - - hash = target.parent.uid + ':' - + (target.parent ? target.parent.children.indexOf(target) : ''); - - if (target._ihash === hash) { - return target._index; - } - target._ihash = hash; - - var self = this; - - this._ei = 0; - - return (function find(el) { - for (var i = 0; i < el.children.length; i++) { - if (el.children[i] === target) { - return target._index = self._ei; - } - self._ei++; - if (find(el.children[i]) !== -1) { - return target._index = self._ei; - } - } - return target._index = -1; - })(this); -}; - /** * Element */ @@ -956,12 +912,20 @@ function Element(options) { var hoverBg = convert(this.options.hoverBg); this.on('mouseover', function() { - if (self._bg == null) self._bg = self.bg; + // XXX Possibly a better alternative for the below workaround. + self._bg = self.bg; + //if (self._bg == null) self._bg = self.bg; self.bg = hoverBg; self.screen.render(); }); this.on('mouseout', function() { + // XXX Workaround + if (0) if (self.parent.type === 'list' + && self === self.parent.items[self.parent.selected] + && self.bg === self.parent.selectedBg) { + return; + } if (self._bg != null) self.bg = self._bg; self.screen.render(); }); @@ -2520,6 +2484,12 @@ function Button(options) { self.screen.render(); }); } + + if (this.options.mouse) { + this.on('click', function() { + self.press(); + }); + } } Button.prototype.__proto__ = Input.prototype;