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 4fab9db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/helpers/pivot/pivot_composer_helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { CellComposerStore } from "../../components/composer/composer/cell_composer_store";
import { tokenColors } from "../../components/composer/composer/composer";
<<<<<<< 18.0
import { Token, getFunctionsFromTokens } from "../../formulas";
||||||| c14a4c9b818a8ea58cac7cf77a3085e7d3af95f8
import { ComposerStore } from "../../components/composer/composer/composer_store";
import { Token, getFunctionsFromTokens } from "../../formulas";
=======
import { ComposerStore } from "../../components/composer/composer/composer_store";
import { getFunctionsFromTokens, Token } from "../../formulas";
>>>>>>> f16d2f34bbd4af8f4cd86497259a2de3077b8c9c
import { EnrichedToken } from "../../formulas/composer_tokenizer";
import { Granularity, PivotField, PivotMeasure } from "../../types";

Expand Down Expand Up @@ -52,6 +60,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 +83,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 4fab9db

Please sign in to comment.