diff --git a/src/plugins/core/cell.ts b/src/plugins/core/cell.ts index 687e047ece..11ce377b90 100644 --- a/src/plugins/core/cell.ts +++ b/src/plugins/core/cell.ts @@ -162,7 +162,7 @@ export class CellPlugin extends CorePlugin implements CoreState { for (let col = zone.left; col <= zone.right; col++) { for (let row = zone.top; row <= zone.bottom; row++) { const cell = this.getters.getCell({ sheetId, col, row }); - if (cell) { + if (cell?.isFormula || cell?.content) { this.dispatch("UPDATE_CELL", { sheetId: sheetId, content: "", @@ -200,7 +200,6 @@ export class CellPlugin extends CorePlugin implements CoreState { for (let zone of recomputeZones(zones)) { for (let col = zone.left; col <= zone.right; col++) { for (let row = zone.top; row <= zone.bottom; row++) { - // commandHelpers.updateCell(sheetId, col, row, { style: undefined}); this.dispatch("UPDATE_CELL", { sheetId, col, diff --git a/tests/cells/cell_plugin.test.ts b/tests/cells/cell_plugin.test.ts index feba2235ba..9e83fc1633 100644 --- a/tests/cells/cell_plugin.test.ts +++ b/tests/cells/cell_plugin.test.ts @@ -1,7 +1,8 @@ -import { Model } from "../../src"; +import { CoreCommand, CorePlugin, Model } from "../../src"; import { LINK_COLOR } from "../../src/constants"; import { buildSheetLink, toZone } from "../../src/helpers"; import { urlRepresentation } from "../../src/helpers/links"; +import { corePluginRegistry } from "../../src/plugins"; import { CellValueType, CommandResult } from "../../src/types"; import { addColumns, @@ -11,6 +12,7 @@ import { copy, createSheet, deleteColumns, + deleteContent, deleteRows, deleteSheet, paste, @@ -27,6 +29,7 @@ import { getEvaluatedCell, getStyle, } from "../test_helpers/getters_helpers"; +import { addTestPlugin } from "../test_helpers/helpers"; describe("getCellText", () => { test("Update cell with a format is correctly set", () => { @@ -643,4 +646,22 @@ describe("Cell dependencies and tokens are updated", () => { }, }); }); + + test("Do not dispatch UPDATE_CELL subcommands if the content is empty", () => { + let counter = 0; + class SubCommandCounterRange extends CorePlugin { + static getters = []; + handle(command: CoreCommand) { + if (command.type === "UPDATE_CELL") { + counter++; + } + } + } + addTestPlugin(corePluginRegistry, SubCommandCounterRange); + const model = new Model(); + setStyle(model, "A1", { bold: true }); + counter = 0; + deleteContent(model, ["A1"]); + expect(counter).toBe(0); + }); });