Skip to content

Commit

Permalink
[FIX] find_and_replace: hidden cell should not be considered
Browse files Browse the repository at this point in the history
Previously, when hiding row or column, f&r include that values
in search. But if column or row is hidden, cell should not consider in
searched match

closes #2683

Taskid: 3422479
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
  • Loading branch information
jash-odoo committed Jul 19, 2023
1 parent 4924f7f commit 7ab1cae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/plugins/ui/find_and_replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,17 @@ export class FindAndReplacePlugin extends UIPlugin {
* Find matches using the current regex
*/
private findMatches() {
const activeSheetId = this.getters.getActiveSheetId();
const cells = this.getters.getCells(activeSheetId);
const sheetId = this.getters.getActiveSheetId();
const cells = this.getters.getCells(sheetId);
const matches: SearchMatch[] = [];

if (this.toSearch) {
for (const cell of Object.values(cells)) {
const { col, row } = this.getters.getCellPosition(cell.id);
const isColHidden = this.getters.isColHidden(sheetId, col);
const isRowHidden = this.getters.isRowHidden(sheetId, row);
if (isColHidden || isRowHidden) {
continue;
}
if (
cell &&
this.currentSearchRegex &&
Expand Down
21 changes: 20 additions & 1 deletion tests/plugins/find_and_replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Model } from "../../src";
import { args, functionRegistry } from "../../src/functions";
import { toZone } from "../../src/helpers";
import { SearchOptions } from "../../src/plugins/ui/find_and_replace";
import { activateSheet, createSheet, setCellContent } from "../test_helpers/commands_helpers";
import {
activateSheet,
createSheet,
hideRows,
setCellContent,
} from "../test_helpers/commands_helpers";
import { getCellContent, getCellText } from "../test_helpers/getters_helpers";

let model: Model;
Expand Down Expand Up @@ -177,6 +182,20 @@ describe("basic search", () => {
expect(matches).toHaveLength(2);
expect(matchIndex).toStrictEqual(0);
});

test("hidden cells should not be included in match", () => {
model.dispatch("UPDATE_SEARCH", { toSearch: "1", searchOptions });
let matches = model.getters.getSearchMatches();
let matchIndex = model.getters.getCurrentSelectedMatchIndex();
expect(matches).toHaveLength(4);
expect(matchIndex).toStrictEqual(0);
hideRows(model, [1]);
model.dispatch("UPDATE_SEARCH", { toSearch: "1", searchOptions });
matches = model.getters.getSearchMatches();
matchIndex = model.getters.getCurrentSelectedMatchIndex();
expect(matches).toHaveLength(3);
expect(matchIndex).toStrictEqual(0);
});
});
describe("next/previous cycle", () => {
beforeEach(() => {
Expand Down

0 comments on commit 7ab1cae

Please sign in to comment.