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 #3868

Taskid: 3789473
X-original-commit: 3054eb7
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
  • Loading branch information
dhrp-odoo committed Mar 22, 2024
1 parent 7e7b069 commit 389177f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/composer/composer/composer.ts
@@ -1,4 +1,4 @@
import { Component, onMounted, useEffect, useRef, useState } from "@odoo/owl";
import { Component, onMounted, onPatched, useEffect, useRef, useState } from "@odoo/owl";
import { COMPOSER_ASSISTANT_COLOR, DEFAULT_FONT, NEWLINE } from "../../../constants";
import { EnrichedToken } from "../../../formulas/index";
import { functionRegistry } from "../../../functions/index";
Expand Down Expand Up @@ -226,6 +226,13 @@ export class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
useEffect(() => {
this.processContent();
});

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

// ---------------------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions tests/composer/autocomplete_dropdown_component.test.ts
Expand Up @@ -15,8 +15,11 @@ import {
ComposerWrapper,
clearFunctions,
mountComposerWrapper,
mountSpreadsheet,
nextTick,
restoreDefaultFunctions,
startGridComposition,
typeInComposerGrid,
typeInComposerHelper,
} from "../test_helpers/helpers";
jest.mock("../../src/components/composer/content_editable_helper.ts", () =>
Expand Down Expand Up @@ -253,6 +256,20 @@ describe("Functions autocomplete", () => {
fixture.querySelector(".o-autocomplete-value-focus .o-autocomplete-value")!.textContent
).toBe("SUM");
});

test("autocomplete should not appear when typing '=S', clicking outside, and edting back", async () => {
const { model, fixture } = await mountSpreadsheet();
await typeInComposerGrid("=S", true);
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();
});
});

describe("autocomplete functions SUM IF", () => {
Expand Down Expand Up @@ -294,6 +311,19 @@ describe("Autocomplete parenthesis", () => {
expect(getCellText(model, "A1")).toBe("=sum(1,2)");
});

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

model.dispatch("STOP_EDITION");
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 typeInComposer("=sum(1,2)");
await keyDown({ key: "Enter" });
Expand Down

0 comments on commit 389177f

Please sign in to comment.