Skip to content

Commit 06c98e2

Browse files
vaadin-botthevaadinmanDiegoCardoso
authored
fix: do not hide rows/columns for nonexistent freeze pane splits (#8158) (#8194)
Co-authored-by: Patrik Lindström <99639133+thevaadinman@users.noreply.github.com> Co-authored-by: Diego Cardoso <diego@vaadin.com>
1 parent c9a9e28 commit 06c98e2

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

vaadin-spreadsheet-flow-parent/vaadin-spreadsheet-flow-integration-tests/src/test/java/com/vaadin/flow/component/spreadsheet/test/FreezePaneIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ public void hideRowAndFreeze_shouldScrollCorrectly() {
235235
headerRect.getY() + headerRect.getHeight());
236236
}
237237

238+
@Test
239+
public void frozenAndScrolledSheet_headerColumnsRendered() {
240+
loadFile("freeze_and_scroll_test.xlsx");
241+
242+
var firstColumn = getSpreadsheet().getColumnHeader(1);
243+
Assert.assertTrue("Header of column A should have size",
244+
firstColumn.getSize().getWidth() > 0);
245+
}
246+
247+
@Test
248+
public void frozenAndScrolledSheet_headerRowsRendered() {
249+
loadFile("freeze_and_scroll_vertical_test.xlsx");
250+
251+
var firstRowHeader = getSpreadsheet().getRowHeader(1);
252+
Assert.assertTrue("Header of row 1 should have size",
253+
firstRowHeader.getSize().getHeight() > 0);
254+
}
255+
238256
private int getHeaderCount(String selector) {
239257
var headers = findElementsInShadowRoot(By.cssSelector(selector));
240258
return headers.size();

vaadin-spreadsheet-flow-parent/vaadin-spreadsheet-flow/src/main/java/com/vaadin/flow/component/spreadsheet/SpreadsheetFactory.java

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ static void loadMergedRegions(Spreadsheet spreadsheet) {
10451045
* Target Spreadsheet
10461046
*/
10471047
static void loadFreezePane(Spreadsheet spreadsheet) {
1048+
10481049
final Sheet sheet = spreadsheet.getActiveSheet();
10491050
PaneInformation paneInformation = sheet.getPaneInformation();
10501051

@@ -1054,34 +1055,52 @@ static void loadFreezePane(Spreadsheet spreadsheet) {
10541055
// With a large sheet, getTopRow could become negative.
10551056
var topRow = Math.max(0, sheet.getTopRow());
10561057
var leftCol = Math.max(0, sheet.getLeftCol());
1058+
var vSplit = paneInformation.getVerticalSplitPosition();
1059+
var hSplit = paneInformation.getHorizontalSplitPosition();
10571060

10581061
/*
10591062
* In POI, HorizontalSplit means rows and VerticalSplit means
10601063
* columns.
10611064
*
10621065
* In Spreadsheet the meaning is the opposite.
1063-
*/
1064-
spreadsheet.setHorizontalSplitPosition(
1065-
paneInformation.getVerticalSplitPosition() + leftCol);
1066-
1067-
spreadsheet.setVerticalSplitPosition(
1068-
paneInformation.getHorizontalSplitPosition() + topRow);
1069-
1070-
/*
1066+
*
1067+
* POI uses a split position of 0 to mean "no split", so we should
1068+
* not be setting split positions or hiding anything in the case
1069+
* this position is 0.
1070+
*
10711071
* If the view was scrolled down / right when panes were frozen, the
10721072
* invisible frozen rows/columns are effectively hidden in Excel. We
1073-
* mimic this behavior here.
1073+
* attempt to mimic this behavior here by actually hiding the
1074+
* rows/columns, but only if there actually was a split.
10741075
*/
1075-
spreadsheet.setColumnsHidden(
1076-
IntStream.range(0, leftCol).boxed().collect(Collectors
1077-
.toMap(Function.identity(), index -> true)));
1078-
spreadsheet.setRowsHidden(
1079-
IntStream.range(0, topRow).boxed().collect(Collectors
1080-
.toMap(Function.identity(), index -> true)));
1076+
if (vSplit > 0) {
1077+
spreadsheet.setHorizontalSplitPosition(vSplit + leftCol);
1078+
if (leftCol > 0) {
1079+
spreadsheet.setColumnsHidden(IntStream.range(0, leftCol)
1080+
.boxed().collect(Collectors.toMap(
1081+
Function.identity(), index -> true)));
1082+
}
1083+
} else if (leftCol > 0) {
1084+
// TODO: should scroll vertically to restore viewport state
1085+
// This needs API on the Spreadsheet side
1086+
}
1087+
1088+
if (hSplit > 0) {
1089+
spreadsheet.setVerticalSplitPosition(hSplit + topRow);
1090+
if (topRow > 0) {
1091+
spreadsheet.setRowsHidden(IntStream.range(0, topRow).boxed()
1092+
.collect(Collectors.toMap(Function.identity(),
1093+
index -> true)));
1094+
}
1095+
} else if (topRow > 0) {
1096+
// TODO: should scroll vertically to restore viewport state
1097+
// This needs API on the Spreadsheet side
1098+
}
10811099
} else {
10821100
spreadsheet.setVerticalSplitPosition(0);
10831101
spreadsheet.setHorizontalSplitPosition(0);
10841102
}
1103+
10851104
}
10861105

10871106
private static Sheet createNewSheet(Workbook workbook) {

0 commit comments

Comments
 (0)