diff --git a/src/plugins/ui_feature/table_resize_ui.ts b/src/plugins/ui_feature/table_resize_ui.ts index dab63fcb1c..b1ac9da36b 100644 --- a/src/plugins/ui_feature/table_resize_ui.ts +++ b/src/plugins/ui_feature/table_resize_ui.ts @@ -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++) { diff --git a/tests/table/table_resize_ui_plugin.test.ts b/tests/table/table_resize_ui_plugin.test.ts index 1be52c3998..76066c2147 100644 --- a/tests/table/table_resize_ui_plugin.test.ts +++ b/tests/table/table_resize_ui_plugin.test.ts @@ -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; @@ -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"); + }); });