From 3f3a7920921f61fc7def7e8e55e8b0df54058e6c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 6 Oct 2017 22:30:49 -0700 Subject: [PATCH 1/2] Do not change target position when equal amount of cells are replaced --- .../org/fxmisc/flowless/TargetPosition.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/fxmisc/flowless/TargetPosition.java b/src/main/java/org/fxmisc/flowless/TargetPosition.java index 8131c03..7a4dc00 100644 --- a/src/main/java/org/fxmisc/flowless/TargetPosition.java +++ b/src/main/java/org/fxmisc/flowless/TargetPosition.java @@ -62,8 +62,13 @@ public TargetPosition transformByChange( // change before the target item, just update item index return new StartOffStart(itemIndex - removedSize + addedSize, offsetFromStart); } else if(itemIndex >= pos) { - // target item deleted, show the first inserted at the target offset - return new StartOffStart(pos, offsetFromStart); + // target item deleted + if (addedSize == removedSize) { + return this; + } else { + // show the first inserted at the target offset + return new StartOffStart(pos, offsetFromStart); + } } else { // change after the target item, target position not affected return this; @@ -119,8 +124,13 @@ public TargetPosition transformByChange( // change before the target item, just update item index return new EndOffEnd(itemIndex - removedSize + addedSize, offsetFromEnd); } else if(itemIndex >= pos) { - // target item deleted, show the last inserted at the target offset - return new EndOffEnd(pos + addedSize - 1, offsetFromEnd); + // target item deleted + if (addedSize == removedSize) { + return this; + } else { + // show the last inserted at the target offset + return new EndOffEnd(pos + addedSize - 1, offsetFromEnd); + } } else { // change after the target item, target position not affected return this; @@ -165,8 +175,13 @@ public TargetPosition transformByChange( // change before the target item, just update item index return new MinDistanceTo(itemIndex - removedSize + addedSize, minY, maxY); } else if(itemIndex >= pos) { - // target item deleted, show the first inserted - return new MinDistanceTo(pos, Offset.fromStart(0.0), Offset.fromEnd(0.0)); + // target item deleted + if (addedSize == removedSize) { + return this; + } else { + // show the first inserted + return new MinDistanceTo(pos, Offset.fromStart(0.0), Offset.fromEnd(0.0)); + } } else { // change after the target item, target position not affected return this; From 1b7ae6c01a4a2fb6826ea06282e988d5b06f7db0 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 7 Oct 2017 20:28:52 -0700 Subject: [PATCH 2/2] Prevent adding cells under the ground when item index is the last one When VirtualFlow is wrapped in a VirtualizedScrollPane and is scrolled, so that the last cell is being shown, this method should return 0. However, due to a scroll bar temporarily adjusting the viewport length, it returns a value that's roughly the height of the last cell's node. Thus, the call in `fillViewportFrom` will add more cells under the ground and shift them towards the sky. This call then hides the last item and the viewport appears to scroll up by one cell. The change insures that the last index always returns 0 rather than a postive value that causes the cell shift. --- src/main/java/org/fxmisc/flowless/Navigator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/fxmisc/flowless/Navigator.java b/src/main/java/org/fxmisc/flowless/Navigator.java index fb8a701..6bbcccf 100644 --- a/src/main/java/org/fxmisc/flowless/Navigator.java +++ b/src/main/java/org/fxmisc/flowless/Navigator.java @@ -357,8 +357,9 @@ private double distanceFromGround(int itemIndex) { private double distanceFromSky(int itemIndex) { C cell = positioner.getVisibleCell(itemIndex); + int lastIndex = cellListManager.getLazyCellList().size() - 1; return gravity.get() == Gravity.FRONT - ? sizeTracker.getViewportLength() - orientation.maxY(cell) + ? itemIndex == lastIndex ? 0 : sizeTracker.getViewportLength() - orientation.maxY(cell) : orientation.minY(cell); }