Skip to content

Commit

Permalink
[FIX] Composer: pressing enter in the link editor
Browse files Browse the repository at this point in the history
Previously, pressing Enter in the link editor would inadvertently open
the grid composer in edit mode, which was not the expected behavior.
This commit addresses the issue by adding a check in the onInput method
of the composer component.

closes #4002

Taskid: 3796114
X-original-commit: 9fcb43d
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
  • Loading branch information
dhrp-odoo committed Apr 8, 2024
1 parent 10cf3e6 commit 5ca9bb4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/link/link_editor/link_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class LinkEditor extends Component<LinkEditorProps, SpreadsheetChildEnv>
this.save();
}
ev.stopPropagation();
ev.preventDefault();
break;
case "Escape":
this.cancel();
Expand Down
21 changes: 20 additions & 1 deletion tests/components/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import {
getEvaluatedCell,
getSelectionAnchorCellXc,
} from "../test_helpers/getters_helpers";
import { mountComponent, nextTick, typeInComposerHelper } from "../test_helpers/helpers";
import {
mountComponent,
mountSpreadsheet,
nextTick,
typeInComposerHelper,
} from "../test_helpers/helpers";
import { ContentEditableHelper } from "./__mocks__/content_editable_helper";
jest.mock("../../src/components/composer/content_editable_helper", () =>
require("./__mocks__/content_editable_helper")
Expand Down Expand Up @@ -520,6 +525,20 @@ describe("composer", () => {
expect(link?.url).toBe("http://odoo.com");
});

test("Pressing Enter while editing a label does not open grid composer", async () => {
({ model, fixture } = await mountSpreadsheet());
setCellContent(model, "A1", "[label](http://odoo.com)");
await simulateClick(".o-topbar-menu[data-id='insert']");
await simulateClick(".o-menu-item[data-name='insert_link']");
const editor = fixture.querySelector(".o-link-editor");
expect(editor).toBeTruthy();

editor!.querySelectorAll("input")[0].focus();
await keyDown({ key: "Enter" });
expect(fixture.querySelector(".o-link-editor")).toBeFalsy();
expect(model.getters.getEditionMode()).toBe("inactive");
});

describe("change selecting mode when typing specific token value", () => {
const matchingValues = [",", "+", "*", "="];
const mismatchingValues = ["1", '"coucou"', "TRUE", "SUM", "A2"];
Expand Down

0 comments on commit 5ca9bb4

Please sign in to comment.