Skip to content

Commit d05e4ec

Browse files
committed
[FIX] composer: Enter/Tab confirm when assistant is force-closed
When the formula assistant was force-closed, Enter/Tab were swallowed and no action occurred. Users could not confirm edits (including plain text). Composer now tells the store when the assistant is force-closed. Enter/Tab confirm the edit if the assistant is open; otherwise, they stop the edition. Task: 5153666
1 parent eb13639 commit d05e4ec

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

src/components/composer/composer/abstract_composer_store.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,14 @@ export abstract class AbstractComposerStore extends SpreadsheetStore {
930930
this.autoComplete.hide();
931931
}
932932

933-
autoCompleteOrStop(direction: Direction) {
933+
autoCompleteOrStop(direction: Direction, isAutocompleteForcedClosed: boolean = false) {
934934
if (this.editionMode !== "inactive") {
935935
const autoComplete = this.autoComplete;
936-
if (autoComplete.provider && autoComplete.selectedIndex !== undefined) {
936+
if (
937+
!isAutocompleteForcedClosed &&
938+
autoComplete.provider &&
939+
autoComplete.selectedIndex !== undefined
940+
) {
937941
const autoCompleteValue = autoComplete.provider.proposals[autoComplete.selectedIndex]?.text;
938942
if (autoCompleteValue) {
939943
this.autoComplete.provider?.selectProposal(autoCompleteValue);

src/components/composer/composer/composer.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,21 @@ export class Composer extends Component<CellComposerProps, SpreadsheetChildEnv>
385385
private processTabKey(ev: KeyboardEvent, direction: Direction) {
386386
ev.preventDefault();
387387
ev.stopPropagation();
388-
if (!this.assistant.forcedClosed) {
389-
this.props.composerStore.autoCompleteOrStop(direction);
390-
}
388+
389+
this.props.composerStore.autoCompleteOrStop(
390+
direction,
391+
this.assistant.forcedClosed && this.props.composerStore.canBeToggled
392+
);
391393
}
392394

393395
private processEnterKey(ev: KeyboardEvent, direction: Direction) {
394396
ev.preventDefault();
395397
ev.stopPropagation();
396-
if (!this.assistant.forcedClosed) {
397-
this.props.composerStore.autoCompleteOrStop(direction);
398-
}
398+
399+
this.props.composerStore.autoCompleteOrStop(
400+
direction,
401+
this.assistant.forcedClosed && this.props.composerStore.canBeToggled
402+
);
399403
}
400404

401405
private processNewLineEvent(ev: KeyboardEvent) {

tests/composer/autocomplete_dropdown_component.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,16 +350,33 @@ describe("Functions autocomplete", () => {
350350
// hide the auto-complete
351351
await click(fixture, ".fa-times-circle");
352352
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);
353+
354+
// Enter should CONFIRM as-typed (no autocomplete) and stop edition
353355
await keyDown({ key: "Enter" });
354-
expect(composerStore.currentContent).toBe("=SU");
356+
expect(getCellText(model, "A1")).toBe("=SU");
357+
expect(composerStore.editionMode).toBe("inactive");
355358

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

367+
test("after force-closing assistant, plain text in another cell still confirms", async () => {
368+
await typeInComposer("=SU");
369+
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(1);
370+
await click(fixture, ".fa-times-circle");
371+
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);
372+
await keyDown({ key: "Enter" });
373+
374+
await typeInComposer("hello");
375+
await keyDown({ key: "Enter" });
376+
expect(getCellText(model, "A2")).toBe("hello");
377+
expect(parent.env.getStore(CellComposerStore).editionMode).toBe("inactive");
378+
});
379+
363380
test("autocomplete proposal can be automatically expanded", async () => {
364381
addToRegistry(registries.autoCompleteProviders, "test", {
365382
getProposals() {
@@ -441,6 +458,27 @@ describe("Data validation autocomplete", () => {
441458
expect(fixture.querySelector(".fa-times-circle")).toBeFalsy();
442459
expect(fixture.querySelector(".fa-question-circle")).toBeFalsy();
443460
});
461+
462+
test("after force-closing formula assistant, Enter in data validation still selects from dropdown", async () => {
463+
addDataValidation(model, "A1", "id", {
464+
type: "isValueInList",
465+
values: [" 1", "2", "3"],
466+
displayStyle: "arrow",
467+
});
468+
469+
await typeInComposer("=SU");
470+
await click(fixture, ".fa-times-circle");
471+
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(0);
472+
expect(fixture.querySelector(".fa-times-circle")).toBeFalsy();
473+
474+
await keyDown({ key: "Escape" });
475+
await typeInComposer("");
476+
expect(fixture.querySelectorAll(".o-autocomplete-value")).toHaveLength(3);
477+
478+
await keyDown({ key: "ArrowDown" });
479+
await keyDown({ key: "Enter" });
480+
expect(getCellText(model, "A1")).toBe("1");
481+
});
444482
});
445483

446484
describe("Autocomplete parenthesis", () => {

0 commit comments

Comments
 (0)