Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/composer/composer/abstract_composer_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,15 @@ export abstract class AbstractComposerStore extends SpreadsheetStore {
this.autoComplete.hide();
}

autoCompleteOrStop(direction: Direction) {
autoCompleteOrStop(direction: Direction, assistantForcedClosed: boolean = false) {
if (this.editionMode !== "inactive") {
const autoComplete = this.autoComplete;
if (autoComplete.provider && autoComplete.selectedIndex !== undefined) {
const suppressAutocomplete = assistantForcedClosed && this.canBeToggled;
if (
!suppressAutocomplete &&
autoComplete.provider &&
autoComplete.selectedIndex !== undefined
) {
const autoCompleteValue = autoComplete.provider.proposals[autoComplete.selectedIndex]?.text;
if (autoCompleteValue) {
this.autoComplete.provider?.selectProposal(autoCompleteValue);
Expand Down
8 changes: 2 additions & 6 deletions src/components/composer/composer/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,13 @@ export class Composer extends Component<CellComposerProps, SpreadsheetChildEnv>
private processTabKey(ev: KeyboardEvent, direction: Direction) {
ev.preventDefault();
ev.stopPropagation();
if (!this.assistant.forcedClosed) {
this.props.composerStore.autoCompleteOrStop(direction);
}
this.props.composerStore.autoCompleteOrStop(direction, this.assistant.forcedClosed);
}

private processEnterKey(ev: KeyboardEvent, direction: Direction) {
ev.preventDefault();
ev.stopPropagation();
if (!this.assistant.forcedClosed) {
this.props.composerStore.autoCompleteOrStop(direction);
}
this.props.composerStore.autoCompleteOrStop(direction, this.assistant.forcedClosed);
}

private processNewLineEvent(ev: KeyboardEvent) {
Expand Down
40 changes: 39 additions & 1 deletion tests/composer/autocomplete_dropdown_component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,33 @@ describe("Functions autocomplete", () => {
// hide the auto-complete
await click(fixture, ".fa-times-circle");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);

// Enter should CONFIRM as-typed (no autocomplete) and stop edition
await keyDown({ key: "Enter" });
expect(composerStore.currentContent).toBe("=SU");
expect(getCellText(model, "A1")).toBe("=SU");
expect(composerStore.editionMode).toBe("inactive");

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

test("after force-closing assistant, plain text in another cell still confirms", async () => {
await typeInComposer("=SU");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(1);
await click(fixture, ".fa-times-circle");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);
await keyDown({ key: "Enter" });

await typeInComposer("hello");
await keyDown({ key: "Enter" });
expect(getCellText(model, "A2")).toBe("hello");
expect(parent.env.getStore(CellComposerStore).editionMode).toBe("inactive");
});

test("autocomplete proposal can be automatically expanded", async () => {
addToRegistry(registries.autoCompleteProviders, "test", {
getProposals() {
Expand Down Expand Up @@ -441,6 +458,27 @@ describe("Data validation autocomplete", () => {
expect(fixture.querySelector(".fa-times-circle")).toBeFalsy();
expect(fixture.querySelector(".fa-question-circle")).toBeFalsy();
});

test("after force-closing formula assistant, Enter in data validation still selects from dropdown", async () => {
addDataValidation(model, "A1", "id", {
type: "isValueInList",
values: [" 1", "2", "3"],
displayStyle: "arrow",
});

await typeInComposer("=SU");
await click(fixture, ".fa-times-circle");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);
expect(fixture.querySelector(".fa-times-circle")).toBeFalsy();

await keyDown({ key: "Escape" });
await typeInComposer("");
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(3);

await keyDown({ key: "ArrowDown" });
await keyDown({ key: "Enter" });
expect(getCellText(model, "A1")).toBe("1");
});
});

describe("Autocomplete parenthesis", () => {
Expand Down