Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transform a change by using an undeleted visible cell or by ignoring exact replacements #32

Merged
merged 2 commits into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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