Skip to content

Commit

Permalink
[FIX] Composer: weird behavior of autocomplete dropdown
Browse files Browse the repository at this point in the history
Previously, when users typed "=S" in the composer, clicked outside, then
started editing another cell, the autocomplete dropdown remained visible.
Similarly, when they typed "=SUM(" and pressed enter, then edited another
cell, the function assistant persisted.

This commit addresses the problem by ensuring that state values are set
to false whenever the composer is not in edit mode.

closes #3834

Taskid: 3789473
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
  • Loading branch information
dhrp-odoo committed Mar 21, 2024
1 parent 5cba28b commit f4e0d71
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/components/composer/composer/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ export class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
if (!this.isKeyStillDown) {
this.processContent();
}

// Required because typing '=SUM' and double-clicking another cell leaves ShowProvider and ShowDescription true
if (this.env.model.getters.getEditionMode() === "inactive") {
this.processTokenAtCursor();
}
});
}

Expand Down
26 changes: 26 additions & 0 deletions tests/components/autocomplete_dropdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
mountSpreadsheet,
nextTick,
restoreDefaultFunctions,
startGridComposition,
typeInComposerGrid as typeInComposerGridHelper,
} from "../test_helpers/helpers";
import { ContentEditableHelper } from "./__mocks__/content_editable_helper";
Expand Down Expand Up @@ -188,6 +189,19 @@ describe("Functions autocomplete", () => {
});
});

test("autocomplete should not appear when typing '=S', clicking outside, and edting back", async () => {
await typeInComposerGrid("=S");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(2);

model.dispatch("STOP_EDITION");
await nextTick();
expect(fixture.querySelector(".o-autocomplete-dropdown")).toBeFalsy();

await startGridComposition();
await nextTick();
expect(fixture.querySelector(".o-autocomplete-dropdown")).toBeFalsy();
});

test.each(["Enter", "Tab"])(
"=S(A1:A5) + %s complete the function --> =SUM(A1:A5)",
async (buttonkey) => {
Expand Down Expand Up @@ -288,6 +302,18 @@ describe("Autocomplete parenthesis", () => {
expect(getCellText(model, "A1")).toBe("=sum(1,2)");
});

test("=sum( + enter + edit does not show the formula assistant", async () => {
await typeInComposerGrid("=sum(");
expect(fixture.querySelector(".o-formula-assistant-container")).toBeTruthy();

composerEl.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
await nextTick();
expect(fixture.querySelector(".o-formula-assistant-container")).toBeFalsy();

await startGridComposition();
expect(fixture.querySelector(".o-formula-assistant-container")).toBeFalsy();
});

test("=sum(1,2) + enter + edit sum does not add parenthesis", async () => {
await typeInComposerGrid("=sum(1,2)");
composerEl.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
Expand Down

0 comments on commit f4e0d71

Please sign in to comment.