diff --git a/src/plugins/ui/find_and_replace.ts b/src/plugins/ui/find_and_replace.ts index 1e287d11d6..0814bcaa38 100644 --- a/src/plugins/ui/find_and_replace.ts +++ b/src/plugins/ui/find_and_replace.ts @@ -170,11 +170,7 @@ export class FindAndReplacePlugin extends UIPlugin { cell && this.currentSearchRegex && this.currentSearchRegex.test( - this.searchOptions.searchFormulas - ? cell.isFormula() - ? cell.content - : String(cell.evaluated.value) - : String(cell.evaluated.value) + this.searchOptions.searchFormulas ? cell.content : String(cell.evaluated.value) ) ) { const position = this.getters.getCellPosition(cell.id); diff --git a/tests/plugins/find_and_replace.test.ts b/tests/plugins/find_and_replace.test.ts index 2e509a3277..9f2a68a134 100644 --- a/tests/plugins/find_and_replace.test.ts +++ b/tests/plugins/find_and_replace.test.ts @@ -16,7 +16,7 @@ import { unhideRows, updateFilter, } from "../test_helpers/commands_helpers"; -import { getCellContent, getCellText } from "../test_helpers/getters_helpers"; +import { getCellContent, getCellError, getCellText } from "../test_helpers/getters_helpers"; let model: Model; let searchOptions: SearchOptions; @@ -499,6 +499,20 @@ describe("search options", () => { expect(matchIndex).toBe(null); }); + test("Search in formula searches cell content of a cell in error", () => { + const model = new Model(); + setCellContent(model, "A1", "=notASumFunction(2)"); + setCellContent(model, "A2", '=SUM("a")'); + expect(getCellError(model, "A1")).toBeDefined(); + expect(getCellError(model, "A2")).toBeDefined(); + searchOptions.searchFormulas = true; + model.dispatch("UPDATE_SEARCH", { toSearch: "sum", searchOptions }); + const matches = model.getters.getSearchMatches(); + expect(matches).toHaveLength(2); + expect(matches[0]).toStrictEqual({ col: 0, row: 0, selected: true }); + expect(matches[1]).toStrictEqual({ col: 0, row: 1, selected: false }); + }); + test("Combine matching case / matching entire cell / search in formulas", () => { model.dispatch("UPDATE_SEARCH", { toSearch: "hell", searchOptions }); let matches = model.getters.getSearchMatches();