diff --git a/README.md b/README.md index 0438abd..4318987 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,8 @@ The screen on which every other node renders. - **focusNext()** - focus next element in the index. - **focusPush(element)** - push element on the focus stack (equivalent to `screen.focused = el`). - **focusPop()/focusLast()** - pop element off the focus stack. +- **saveFocus()** - save the focused element. +- **restoreFocus()** - restore the saved focused element. #### Element (from Node) diff --git a/lib/widget.js b/lib/widget.js index 822e838..6719c55 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -675,6 +675,17 @@ Screen.prototype.focusPop = function() { return this.history.pop(); }; +Screen.prototype.saveFocus = function() { + return this._savedFocus = this.focused; +}; + +Screen.prototype.restoreFocus = function() { + if (!this._savedFocus) return; + this._savedFocus.focus(); + delete this._savedFocus; + return this.focused; +}; + Screen.prototype.__defineGetter__('focused', function() { return this.history[this.history.length-1]; });