Skip to content

Commit

Permalink
Merge pull request #32 from JordanMartinez/fixViewportBug
Browse files Browse the repository at this point in the history
Transform a change by using an undeleted visible cell or by ignoring exact replacements
  • Loading branch information
JordanMartinez authored Oct 8, 2017
2 parents d49214b + 1b7ae6c commit 31a1b17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/fxmisc/flowless/Navigator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
27 changes: 21 additions & 6 deletions src/main/java/org/fxmisc/flowless/TargetPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 31a1b17

Please sign in to comment.