Skip to content

Commit

Permalink
[FIX] composer: don't auto-complete when hidden
Browse files Browse the repository at this point in the history
Steps to reproduce:

- type in a formula =SU
- close the aut-completes with the cross at the top right corner
- hit Enter

=> the formula is completed to =SUM(

closes #4972

Task: 4176433
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
  • Loading branch information
LucasLefevre committed Sep 24, 2024
1 parent ca638d9 commit 06ad5fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/composer/composer/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ export class Composer extends Component<CellComposerProps, SpreadsheetChildEnv>
}

private autoComplete(value: string) {
if (!value) {
if (!value || this.assistant.forcedClosed) {
return;
}
this.autoCompleteState.provider?.selectProposal(value);
Expand Down
18 changes: 18 additions & 0 deletions tests/composer/autocomplete_dropdown_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ describe("Functions autocomplete", () => {
expect(fixture.querySelector(".o-formula-assistant-container")).toBeTruthy();
expect(fixture.querySelector("#formula-assistant-details")?.className).not.toContain("show");
});

test("cannot auto-complete when it is closed", async () => {
await typeInComposer("=SU");
expect(document.activeElement).toBe(composerEl);
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(1);

// hide the auto-complete
await click(fixture, ".fa-times-circle");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);
await keyDown({ key: "Enter" });
expect(composerStore.currentContent).toBe("=SU");

// show it again
await click(fixture, ".fa-question-circle");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(1);
await keyDown({ key: "Enter" });
expect(composerStore.currentContent).toBe("=SUM(");
});
});

describe("autocomplete functions SUM IF", () => {
Expand Down

0 comments on commit 06ad5fe

Please sign in to comment.