diff options
author | Florrie <towerofnix@gmail.com> | 2018-06-04 09:57:49 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-06-04 09:57:49 -0300 |
commit | 6e0fa96243902c4354764c2edc79edf1190280fc (patch) | |
tree | de520a1815b73513a97a20d00f2f8c03831e8d46 | |
parent | 01707d9e6376ff04a7b39381eb6b131717a721fe (diff) |
ListScrollForm.scrollToEnd function
-rw-r--r-- | ui/form/ListScrollForm.js | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/ui/form/ListScrollForm.js b/ui/form/ListScrollForm.js index 581c82f..fe7ef0e 100644 --- a/ui/form/ListScrollForm.js +++ b/ui/form/ListScrollForm.js @@ -96,19 +96,7 @@ module.exports = class ListScrollForm extends Form { // we should move the view so that the item is the farthest right (of all // the visible items). if (this.getItemPos(sel) > this.formEdge + this.scrollSize) { - // We can decide how many items to scroll past by moving forward until - // our item's far edge is visible. - - let i - let edge = this.formEdge - - for (i = 0; i < this.inputs.length; i++) { - if (this.getItemPos(sel) <= edge) break - edge += this.inputs[i][this.sizeProp] - } - - // Now that we have the right index to scroll to, apply it! - this.scrollItems = i + this.scrollElementIntoEndOfView(sel) } // Adjusting the number of scroll items is much simpler to deal with if @@ -143,11 +131,30 @@ module.exports = class ListScrollForm extends Form { this.scrollItems += this.h if (this.curIndex >= this.inputs.length) { this.curIndex = this.inputs.length - 1 - this.scrollItems = Math.max(0, this.inputs.length - this.h) + this.scrollToEnd() } this.updateSelectedElement() } + scrollElementIntoEndOfView(element) { + // We can decide how many items to scroll past by moving forward until + // the item's far edge is visible. + let i + let edge = this.formEdge + for (i = 0; i < this.inputs.length; i++) { + if (this.getItemPos(element) <= edge) break + edge += this.inputs[i][this.sizeProp] + } + + // Now that we have the right index to scroll to, apply it! + this.scrollItems = i + } + + scrollToEnd() { + this.scrollElementIntoEndOfView(this.inputs[this.inputs.length - 1]) + this.fixLayout() + } + getItemPos(item) { // Gets the position of the item in an unscrolled view. |