Skip to content

Commit 082efc2

Browse files
committed
[FIX] table: "delete table" menu item does not always work
The menu item "delete table" was not working if a table was in the selection but not on the active cell. This commit changes it to be consistent with "Edit table", it will now delete the first table in the selection. closes #8827 Task: 6247743 X-original-commit: 9d39f5d Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
1 parent 77cb2a1 commit 082efc2

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/actions/menu_items_actions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,12 @@ export const INSERT_TABLE = (env: SpreadsheetChildEnv) => {
631631
};
632632

633633
export const DELETE_SELECTED_TABLE = (env: SpreadsheetChildEnv) => {
634-
const position = env.model.getters.getActivePosition();
635-
const table = env.model.getters.getTable(position);
634+
const table = env.model.getters.getFirstTableInSelection();
636635
if (!table) {
637636
return;
638637
}
639638
env.model.dispatch("REMOVE_TABLE", {
640-
sheetId: position.sheetId,
639+
sheetId: env.model.getters.getActiveSheetId(),
641640
target: [table.range.zone],
642641
});
643642
};

tests/menus/menu_items_registry.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,15 @@ describe("Menu Item actions", () => {
17731773
expect(model.getters.getTable({ sheetId, row: 0, col: 0 })).toBeUndefined();
17741774
});
17751775

1776+
test("Delete table (cellRegistry) works with a table in the selection but not on the active cell", async () => {
1777+
createTable(model, "A2:A5");
1778+
expect(model.getters.getTable({ sheetId, row: 1, col: 0 })).toBeDefined();
1779+
1780+
setSelection(model, ["A1:A2"], { anchor: "A1" });
1781+
await doAction(["delete_table"], env, cellMenuRegistry);
1782+
expect(model.getters.getTable({ sheetId, row: 1, col: 0 })).toBeUndefined();
1783+
});
1784+
17761785
test("Delete table (cellRegistry) on a dynamic table", async () => {
17771786
setCellContent(model, "A1", "=MUNIT(5)");
17781787
createDynamicTable(model, "A1");

0 commit comments

Comments
 (0)