mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-24 18:00:45 +00:00
Revert "possibly a better fix for form focusing. see #38."
This reverts commit 7965ee581c5783c1a9531db73408dd000d1f87c3.
This commit is contained in:
parent
7965ee581c
commit
9814f832fb
@ -4382,23 +4382,36 @@ Form.prototype.__proto__ = Box.prototype;
|
||||
Form.prototype.type = 'form';
|
||||
|
||||
Form.prototype._refresh = function() {
|
||||
var out = [];
|
||||
// XXX Possibly remove this if statement and refresh on every focus.
|
||||
// Also potentially only include *visible* focusable elements.
|
||||
// This would remove the need to check for _selected.visible in previous()
|
||||
// and next().
|
||||
if (!this._children) {
|
||||
var out = [];
|
||||
|
||||
this.children.forEach(function fn(el) {
|
||||
if (el.keyable && el.visible) out.push(el);
|
||||
el.children.forEach(fn);
|
||||
});
|
||||
this.children.forEach(function fn(el) {
|
||||
if (el.keyable) out.push(el);
|
||||
el.children.forEach(fn);
|
||||
});
|
||||
|
||||
this._children = out;
|
||||
this._children = out;
|
||||
}
|
||||
};
|
||||
|
||||
Form.prototype._visible = function() {
|
||||
return !!this._children.filter(function(el) {
|
||||
return el.visible;
|
||||
}).length;
|
||||
};
|
||||
|
||||
Form.prototype.next = function() {
|
||||
this._refresh();
|
||||
|
||||
if (!this._children.length) return;
|
||||
if (!this._visible()) return;
|
||||
|
||||
if (!this._selected) {
|
||||
this._selected = this._children[0];
|
||||
if (!this._selected.visible) return this.next();
|
||||
// return this._selected;
|
||||
if (this.screen.focused !== this._selected) return this._selected;
|
||||
}
|
||||
@ -4406,20 +4419,23 @@ Form.prototype.next = function() {
|
||||
var i = this._children.indexOf(this._selected);
|
||||
if (!~i || !this._children[i + 1]) {
|
||||
this._selected = this._children[0];
|
||||
if (!this._selected.visible) return this.next();
|
||||
return this._selected;
|
||||
}
|
||||
|
||||
this._selected = this._children[i + 1];
|
||||
if (!this._selected.visible) return this.next();
|
||||
return this._selected;
|
||||
};
|
||||
|
||||
Form.prototype.previous = function() {
|
||||
this._refresh();
|
||||
|
||||
if (!this._children.length) return;
|
||||
if (!this._visible()) return;
|
||||
|
||||
if (!this._selected) {
|
||||
this._selected = this._children[this._children.length - 1];
|
||||
if (!this._selected.visible) return this.previous();
|
||||
// return this._selected;
|
||||
if (this.screen.focused !== this._selected) return this._selected;
|
||||
}
|
||||
@ -4427,10 +4443,12 @@ Form.prototype.previous = function() {
|
||||
var i = this._children.indexOf(this._selected);
|
||||
if (!~i || !this._children[i - 1]) {
|
||||
this._selected = this._children[this._children.length - 1];
|
||||
if (!this._selected.visible) return this.previous();
|
||||
return this._selected;
|
||||
}
|
||||
|
||||
this._selected = this._children[i - 1];
|
||||
if (!this._selected.visible) return this.previous();
|
||||
return this._selected;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user