From d625d57aa4ec89dbf4b37a1ea27f3a3c2989db73 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Mon, 16 Aug 2021 15:28:57 +0530 Subject: [PATCH] Fix lastIndex Signed-off-by: RMidhunSuresh --- src/platform/web/ui/general/ItemRange.js | 6 +++--- src/platform/web/ui/general/LazyListView.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platform/web/ui/general/ItemRange.js b/src/platform/web/ui/general/ItemRange.js index 53627aa4..494f5dcb 100644 --- a/src/platform/web/ui/general/ItemRange.js +++ b/src/platform/web/ui/general/ItemRange.js @@ -37,7 +37,7 @@ export class ItemRange { } containsIndex(idx) { - return idx >= this.topCount && idx < this.lastIndex; + return idx >= this.topCount && idx <= this.lastIndex; } expand(amount) { @@ -56,7 +56,7 @@ export class ItemRange { } get lastIndex() { - return this.topCount + this.renderCount; + return this.topCount + this.renderCount - 1; } totalSize() { @@ -105,7 +105,7 @@ export class ItemRange { return {toRemove, toAdd, scrollDirection}; } const bisection1 = {start: Math.min(this.topCount, range.topCount), end: Math.max(this.topCount, range.topCount) - 1}; - const bisection2 = {start: Math.min(this.lastIndex, range.lastIndex), end: Math.max(this.lastIndex, range.lastIndex)}; + const bisection2 = {start: Math.min(this.lastIndex, range.lastIndex) + 1, end: Math.max(this.lastIndex, range.lastIndex)}; // When scrolling down, bisection1 needs to be removed and bisection2 needs to be added // When scrolling up, vice versa const toRemove = scrollDirection === ScrollDirection.downwards ? bisection1 : bisection2; diff --git a/src/platform/web/ui/general/LazyListView.js b/src/platform/web/ui/general/LazyListView.js index c064a2b5..3213ffee 100644 --- a/src/platform/web/ui/general/LazyListView.js +++ b/src/platform/web/ui/general/LazyListView.js @@ -73,7 +73,7 @@ export class LazyListView extends ListView { const array = []; let i = 0; for (const item of this._list) { - if (i >= start && i < end) { + if (i >= start && i <= end) { array.push(item); } i = i + 1; @@ -201,7 +201,7 @@ export class LazyListView extends ListView { this._renderRange = new ItemRange(topCount, renderCount - 1, bottomCount); } else { - const child = this._childCreator(this._itemAtIndex(this._renderRange.lastIndex - 1)); + const child = this._childCreator(this._itemAtIndex(this._renderRange.lastIndex)); this._childInstances.push(child); this._root.appendChild(mountView(child, this._mountArgs)); this._renderRange = new ItemRange(topCount, renderCount, bottomCount - 1);