Skip to content

Commit

Permalink
[FIX] autocomplete: Stop the range selection after selecting a pivot …
Browse files Browse the repository at this point in the history
…proposal

The proposal selection of pivot autocomplete would put the composer in
an invalid state where we inserted some text while in range selection
mode without modifying the said state.

How to reproduce:
- Go to a runbot and insert a pivot in a spreadsheet
- type =pivot(
- Your have the dropddown taht suggests the id 1
- type enter to select it
--> your composer has =pivot(1 as content
- use the arrowkeys to the up/down
--> It pipes a cell reference next to the pivotID

Task: 4176481
X-original-commit: e02a432
  • Loading branch information
rrahir committed Sep 30, 2024
1 parent f0d1602 commit 5d52e2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/helpers/pivot/pivot_composer_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function insertTokenAfterArgSeparator(
// replace the whole token
start = tokenAtCursor.start;
}
this.composer.stopComposerRangeSelection();
this.composer.changeComposerCursorSelection(start, end);
this.composer.replaceComposerCursorSelection(value);
}
Expand All @@ -74,6 +75,7 @@ export function insertTokenAfterLeftParenthesis(
// replace the whole token
start = tokenAtCursor.start;
}
this.composer.stopComposerRangeSelection();
this.composer.changeComposerCursorSelection(start, end);
this.composer.replaceComposerCursorSelection(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe("spreadsheet pivot auto complete", () => {
);
for (const func of ["PIVOT", "PIVOT.HEADER", "PIVOT.VALUE"]) {
composer.startEdition(`=${func}(`);
expect(composer.isSelectingRange).toBeTruthy();

const autoComplete = composer.autocompleteProvider;
expect(autoComplete?.proposals).toEqual([
{
Expand All @@ -41,6 +43,8 @@ describe("spreadsheet pivot auto complete", () => {
]);
autoComplete?.selectProposal(autoComplete?.proposals[0].text);
expect(composer.currentContent).toBe(`=${func}(1`);
// range selection stops
expect(composer.isSelectingRange).toBeFalsy();
expect(composer.autocompleteProvider).toBeUndefined();
composer.cancelEdition();
}
Expand Down

0 comments on commit 5d52e2a

Please sign in to comment.