From c260bb9a027bdc01f8f6c1231c14c84effcbbfa8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 9 Jun 2013 15:52:22 -0500 Subject: [PATCH] add focus history. --- lib/widget.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/widget.js b/lib/widget.js index 49399d3..4818181 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -142,7 +142,8 @@ function Screen(options) { bottom: this.bottom = 0 }; - this.focused = null; + //this.focused = null; + this.history = []; this.clickable = []; this.input = []; this.grabKeys = false; @@ -449,6 +450,26 @@ Screen.prototype.focusNext = function() { return this.focus(1); }; +Screen.prototype.focusPush = function(el) { + if (this.history.length === 10) { + this.history.shift(); + } + this.history.push(el); +}; + +Screen.prototype.focusLast = +Screen.prototype.focusPop = function() { + return this.history.pop(); +}; + +Screen.prototype.__defineGetter__('focused', function() { + return this.history[this.history.length-1]; +}); + +Screen.prototype.__defineSetter__('focused', function(el) { + return this.focusPush(el); +}); + Screen.prototype.clearRegion = function(xi, xl, yi, yl) { return this.fillRegion(this.dattr, ' ', xi, xl, yi, yl); };