From a29fdf1c7482bd66b2454d73ba02cbe11e922969 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 13 Feb 2015 01:18:20 -0800 Subject: [PATCH] fix hover text and demonstrate it better. --- lib/widget.js | 12 ++++++++++-- test/widget.js | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 5ea5295..ce4f8b5 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -2520,7 +2520,8 @@ Element.prototype.setHover = function(options) { }); this.on('mouse', function(data) { - if (!self._hover._.over) return; + // XXX Does not work as well as it should: + // if (!self._hover._.over) return; var el = self._hover , x = data.x @@ -2533,7 +2534,7 @@ Element.prototype.setHover = function(options) { y -= el.rtop; } - self._hover.rleft = x; + self._hover.rleft = x + 1; self._hover.rtop = y; self.screen.render(); @@ -2544,6 +2545,13 @@ Element.prototype.setHover = function(options) { self._hover.detach(); self.screen.render(); }); + + this.screen.on('element mouseover', function(el) { + if (el === self || el === self._hover) return; + self._hover._.over = false; + self._hover.detach(); + self.screen.render(); + }); }; Element.prototype.removeHover = function() { diff --git a/test/widget.js b/test/widget.js index bf88729..f3f3b0c 100644 --- a/test/widget.js +++ b/test/widget.js @@ -99,6 +99,10 @@ var list = blessed.list({ screen.append(list); list.select(0); +list.items.forEach(function(item) { + item.setHover(item.getText().trim()); +}); + list.prepend(blessed.text({ left: 2, content: ' My list '