Skip to content

Commit 1158339

Browse files
eduardsdvJohan Vos
authored andcommitted
8276167: VirtualFlow.scrollToTop doesn't scroll to the top of the last element
Reviewed-by: aghaisas, jvos
1 parent ff6e8d5 commit 1158339

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/skin/VirtualFlow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ private boolean tryScrollOneCell(int targetIndex, boolean downOrRight) {
15811581
public void scrollToTop(int index) {
15821582
boolean posSet = false;
15831583

1584-
if (index >= getCellCount() - 1) {
1584+
if (index > getCellCount() - 1) {
15851585
setPosition(1);
15861586
posSet = true;
15871587
} else if (index < 0) {

modules/javafx.controls/src/test/java/test/javafx/scene/control/ListViewKeyInputTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,11 +1861,11 @@ private boolean isAnchor(int index) {
18611861
final int diff = 99 - leadSelectedIndex;
18621862
assertEquals(99 - diff, leadSelectedIndex);
18631863
assertEquals(99 - diff, fm.getFocusedIndex());
1864-
assertEquals(7, selectedIndicesCount);
1864+
assertEquals(8, selectedIndicesCount);
18651865

18661866
keyboard.doKeyPress(KeyCode.PAGE_UP, KeyModifier.SHIFT);
1867-
assertEquals(99 - diff * 2, sm.getSelectedIndex());
1868-
assertEquals(selectedIndicesCount * 2 - 1, sm.getSelectedIndices().size());
1867+
assertEquals(99 - diff * 2 + 1, sm.getSelectedIndex());
1868+
assertEquals(selectedIndicesCount * 2 - 2, sm.getSelectedIndices().size());
18691869

18701870
keyboard.doKeyPress(KeyCode.PAGE_DOWN, KeyModifier.SHIFT);
18711871
assertEquals(leadSelectedIndex, sm.getSelectedIndex());

modules/javafx.controls/src/test/java/test/javafx/scene/control/TreeTableViewTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3660,7 +3660,7 @@ protected <T> void assert_rt35857(ObservableList<T> items, MultipleSelectionMode
36603660
// However, for now, we'll test on the assumption that across all
36613661
// platforms we only get one extra cell created, and we can loosen this
36623662
// up if necessary.
3663-
assertEquals(cellCountAtStart + 13, rt36452_instanceCount);
3663+
assertEquals(cellCountAtStart + 14, rt36452_instanceCount);
36643664

36653665
sl.dispose();
36663666
}

modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/VirtualFlowTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,43 @@ private void assertLastCellInsideViewport(boolean vertical) {
11431143
assertEquals("Last cell must end on viewport size", viewportLength, (cellPosition + cellLength), 0.1);
11441144
}
11451145

1146+
@Test
1147+
public void testScrollToTopOfLastLargeCell() {
1148+
double flowHeight = 150;
1149+
int cellCount = 2;
1150+
1151+
flow = new VirtualFlowShim<>();
1152+
flow.setCellFactory(p -> new CellStub(flow) {
1153+
@Override
1154+
protected double computePrefHeight(double width) {
1155+
return getIndex() == cellCount -1 ? 200 : 100;
1156+
}
1157+
1158+
@Override
1159+
protected double computeMinHeight(double width) {
1160+
return computePrefHeight(width);
1161+
}
1162+
1163+
@Override
1164+
protected double computeMaxHeight(double width) {
1165+
return computePrefHeight(width);
1166+
}
1167+
});
1168+
flow.setVertical(true);
1169+
1170+
flow.resize(50,flowHeight);
1171+
flow.setCellCount(cellCount);
1172+
pulse();
1173+
1174+
flow.scrollToTop(cellCount - 1);
1175+
pulse();
1176+
1177+
IndexedCell<?> cell = flow.getCell(cellCount - 1);
1178+
double cellPosition = flow.getCellPosition(cell);
1179+
1180+
assertEquals("Last cell must be aligned to top of the viewport", 0, cellPosition, 0.1);
1181+
}
1182+
11461183
@Test
11471184
public void testImmediateScrollTo() {
11481185
flow.setCellCount(100);

0 commit comments

Comments
 (0)