From 2a9243dfd26aa9aaeb34a28caa59f8953c0a0dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Fri, 13 Sep 2024 13:25:53 +0000 Subject: [PATCH] [FIX] autocomplete: Stop the range selection after selecting a pivot proposal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 closes odoo/o-spreadsheet#5035 Task: 4176481 X-original-commit: d89d673be1e6d7e33bc48bf5f081798b9acc6d89 Signed-off-by: Lucas Lefèvre (lul) Signed-off-by: Rémi Rahir (rar) --- src/helpers/pivot/pivot_composer_helpers.ts | 2 ++ .../composer/auto_complete/pivot_auto_complete_store.test.ts | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/helpers/pivot/pivot_composer_helpers.ts b/src/helpers/pivot/pivot_composer_helpers.ts index 08cb962f99..d2938fdde3 100644 --- a/src/helpers/pivot/pivot_composer_helpers.ts +++ b/src/helpers/pivot/pivot_composer_helpers.ts @@ -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); } @@ -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); } diff --git a/tests/composer/auto_complete/pivot_auto_complete_store.test.ts b/tests/composer/auto_complete/pivot_auto_complete_store.test.ts index 2615d89918..86c6f2cc8c 100644 --- a/tests/composer/auto_complete/pivot_auto_complete_store.test.ts +++ b/tests/composer/auto_complete/pivot_auto_complete_store.test.ts @@ -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([ { @@ -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(); }