Skip to content

Commit

Permalink
[FIX] header_overlay: select col when there is a single row
Browse files Browse the repository at this point in the history
The getter `findFirstVisibleColRowIndex` was bugged and skipped the last
col/row of the sheet. This meant that we couldn't select a row (or col)
if there was a single col (or row) in the sheet.

Odoo task 3204730

Part-of: #2384
  • Loading branch information
hokolomopo committed Apr 20, 2023
1 parent 098648c commit 39de0b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/ui_feature/header_visibility_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class HeaderVisibilityUIPlugin extends UIPlugin {
findFirstVisibleColRowIndex(sheetId: UID, dimension: Dimension) {
const numberOfHeaders = this.getters.getNumberHeaders(sheetId, dimension);

for (let i = 0; i < numberOfHeaders - 1; i++) {
for (let i = 0; i < numberOfHeaders; i++) {
if (dimension === "COL" && !this.isColHidden(sheetId, i)) {
return i;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/components/overlay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { lettersToNumber, toXC, toZone } from "../../src/helpers/index";
import { Model } from "../../src/model";
import {
deleteColumns,
deleteRows,
hideColumns,
hideRows,
merge,
Expand Down Expand Up @@ -155,6 +157,14 @@ describe("Resizer component", () => {
expect(model.getters.getSelectedZones()).toEqual([toZone("C1:C10")]);
});

test("On a sheet with a single row, can click a header to select a column", async () => {
deleteRows(model, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
expect(model.getters.getNumberRows(model.getters.getActiveSheetId())).toBe(1);
await selectColumn("C");
expect(model.getters.getSelectedZones()[0]).toEqual({ left: 2, top: 0, right: 2, bottom: 0 });
expect(getSelectionAnchorCellXc(model)).toBe("C1");
});

test("resizing a column does not change the selection", async () => {
const index = lettersToNumber("C");
const x = model.getters.getColDimensions(model.getters.getActiveSheetId(), index)!.start + 1;
Expand All @@ -177,6 +187,14 @@ describe("Resizer component", () => {
expect(getSelectionAnchorCellXc(model)).toBe("A3");
});

test("In a sheet with a single column, can click on a row-header to select a row", async () => {
deleteColumns(model, ["B", "C", "D", "E", "F", "G", "H", "I", "J"]);
expect(model.getters.getNumberCols(model.getters.getActiveSheetId())).toBe(1);
await selectRow(2);
expect(model.getters.getSelectedZones()[0]).toEqual({ left: 0, top: 2, right: 0, bottom: 2 });
expect(getSelectionAnchorCellXc(model)).toBe("A3");
});

test("can select multiple rows/cols", async () => {
await selectRow(2);
expect(model.getters.getSelectedZones()[0]).toEqual({ left: 0, top: 2, right: 9, bottom: 2 });
Expand Down

0 comments on commit 39de0b7

Please sign in to comment.