Skip to content

Commit

Permalink
[IMP] LinkDisplay: update grid selection before opening the editor
Browse files Browse the repository at this point in the history
Currently, a user can open the link editor of a cell while hovering it
but not selectd. This behaviour is counterintuitive as once the link
editor is opened, we will close it if we change the selection.

This revision ensures that the link editor target and the selection are
synchronized upon the initialization of the the former.

closes #3809

Task: 3793859
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
rrahir authored and LucasLefevre committed Mar 22, 2024
1 parent 8a63dbe commit 09ac577
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/link/link_display/link_display.ts
Expand Up @@ -103,6 +103,7 @@ export class LinkDisplay extends Component<LinkDisplayProps, SpreadsheetChildEnv

edit() {
const { col, row } = this.props.cellPosition;
this.env.model.selection.selectCell(col, row);
this.cellPopovers.open({ col, row }, "LinkEditor");
}

Expand Down
24 changes: 22 additions & 2 deletions tests/link/link_display_component.test.ts
@@ -1,6 +1,12 @@
import { Model, Spreadsheet } from "../../src";
import { buildSheetLink } from "../../src/helpers";
import { clearCell, createSheet, merge, setCellContent } from "../test_helpers/commands_helpers";
import {
clearCell,
createSheet,
merge,
selectCell,
setCellContent,
} from "../test_helpers/commands_helpers";
import { clickCell, hoverCell, rightClickCell, simulateClick } from "../test_helpers/dom_helper";
import { getCell, getEvaluatedCell } from "../test_helpers/getters_helpers";
import { mountSpreadsheet, nextTick } from "../test_helpers/helpers";
Expand Down Expand Up @@ -179,7 +185,21 @@ describe("link display component", () => {
});
});

test("open link editor", async () => {
test("open link editor selects the related cell in the grid", async () => {
selectCell(model, "A10");
setCellContent(model, "A1", "[label](url.com)");
await hoverCell(model, "A1", 400);
await simulateClick(".o-edit-link");
expect(fixture.querySelector(".o-link-tool")).toBeFalsy();
expect(model.getters.getActivePosition()).toMatchObject({ col: 0, row: 0 });
const editor = fixture.querySelector(".o-link-editor");
expect(editor).toBeTruthy();
const inputs = editor?.querySelectorAll("input")!;
expect(inputs[0].value).toBe("label");
expect(inputs[1].value).toBe("https://url.com");
});

test("open link editor ", async () => {
setCellContent(model, "A1", "[label](url.com)");
await hoverCell(model, "A1", 400);
await simulateClick(".o-edit-link");
Expand Down

0 comments on commit 09ac577

Please sign in to comment.