diff --git a/lib/widget.js b/lib/widget.js index 245d04f..cff2474 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -139,8 +139,8 @@ Screen.prototype._listenMouse = function(el, hover) { left = el.left + (el.border ? 1 : 0); top = el.top + (el.border ? 1 : 0); if (el.parent.childBase != null) top -= el.parent.childBase; - if (data.x >= left && data.x <= left + el.width - && data.y >= top && data.y <= top + el.height) { + if (data.x > left && data.x <= left + el.width + && data.y > top && data.y <= top + el.height) { el.emit('mouse', data); if (data.action === 'mouseup') { el.emit('click', data); @@ -148,7 +148,6 @@ Screen.prototype._listenMouse = function(el, hover) { el.emit('hover', data); } el.emit(data.action, data); - break; } } self.emit('mouse', data); @@ -161,6 +160,10 @@ Screen.prototype._listenKeys = function(el) { if (el) { this.input.push(el); + //if (this.mouse) + //el.on('click', function() { + // el.focus(); + //}); } if (this._listenedKeys) return; @@ -1020,6 +1023,18 @@ function List(options) { if (this.children.length) { this.select(0); } + + if (this.mouse) { + self.on('wheeldown', function(data) { + self.select(self.selected + 2); + self.screen.render(); + }); + + self.on('wheelup', function(data) { + self.select(self.selected - 2); + self.screen.render(); + }); + } } List.prototype.__proto__ = ScrollableBox.prototype; @@ -1043,26 +1058,12 @@ List.prototype.add = function(item) { this.append(item); this.items.push(item); - if (!this.mouse) return; - - item.on('click', function(data) { - self.select(item); - self.screen.render(); - }); - - // Temporary workaround: - // We cannot bind to clickable events on the list because the parent will - // receive *all* clickable events in that particular area of the screen. - // Possibly fix in the future by emitting events through tree traversal as - // well as bubbling events. - item.on('wheeldown', function(data) { - self.select(self.selected + 2); - self.screen.render(); - }); - item.on('wheelup', function(data) { - self.select(self.selected - 2); - self.screen.render(); - }); + if (this.mouse) { + item.on('click', function(data) { + self.select(item); + self.screen.render(); + }); + } }; List.prototype._remove = List.prototype.remove; diff --git a/test/widget.js b/test/widget.js index 460498f..2431654 100644 --- a/test/widget.js +++ b/test/widget.js @@ -114,6 +114,10 @@ list.on('keypress', function(ch, key) { } }); +list.on('click', function() { + list.focus(); +}); + var progress = new blessed.ProgressBar({ screen: screen, parent: screen, @@ -161,6 +165,10 @@ var stext = new blessed.ScrollableText({ bottom: 0 }); +stext.on('click', function() { + stext.focus(); +}); + screen.append(stext); stext.on('keypress', function(ch, key) { if (key.name === 'up') {