Skip to content

Commit

Permalink
[IMP] table: select bottom right on resize
Browse files Browse the repository at this point in the history
closes #5295

Task: 4373825
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
fdamhaut committed Dec 11, 2024
1 parent f2e4a38 commit a6bb4c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/plugins/ui_feature/table_resize_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export class TableResizeUI extends UIPlugin {
const table = this.getters.getCoreTableMatchingTopLeft(cmd.sheetId, cmd.zone);
this.dispatch("UPDATE_TABLE", { ...cmd });

if (!table || !table.config.automaticAutofill) return;

const oldTableZone = table.range.zone;
if (!table) return;
const newTableZone = this.getters.getRangeFromRangeData(cmd.newTableRange).zone;
this.selection.selectCell(newTableZone.right, newTableZone.bottom);
if (!table.config.automaticAutofill) return;
const oldTableZone = table.range.zone;

if (newTableZone.bottom >= oldTableZone.bottom) {
for (let col = newTableZone.left; col <= newTableZone.right; col++) {
Expand Down
10 changes: 9 additions & 1 deletion tests/table/table_resize_ui_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
resizeTable,
setCellContent,
} from "../test_helpers/commands_helpers";
import { getCell } from "../test_helpers/getters_helpers";
import { getActivePosition, getCell } from "../test_helpers/getters_helpers";

let model: Model;
let sheetId: UID;
Expand Down Expand Up @@ -58,4 +58,12 @@ describe("Table resize", () => {
resizeTable(model, "A1", "A1:A6");
expect(getCell(model, "A6")?.content).toBe("=B6");
});

test("Resize a table change selection to bottom right corner", () => {
createTable(model, "A1:B4");
resizeTable(model, "A1", "A1:C6");
expect(getActivePosition(model)).toBe("C6");
resizeTable(model, "A1", "A1:B2");
expect(getActivePosition(model)).toBe("B2");
});
});

0 comments on commit a6bb4c9

Please sign in to comment.