From 401c12682ea16f0da49d1a0c092b18d1d6755d44 Mon Sep 17 00:00:00 2001 From: Yunus M Date: Tue, 13 May 2025 23:28:39 +0530 Subject: [PATCH] feat: handle multie select functions --- .../QueryAggregation/QueryAggregationSelect.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx b/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx index 2e82859560b3..3af57c447ff3 100644 --- a/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx +++ b/frontend/src/components/QueryBuilderV2/QueryAggregation/QueryAggregationSelect.tsx @@ -157,10 +157,21 @@ function QueryAggregationSelect(): JSX.Element { ); const lastOpenParen = currentText.lastIndexOf('('); const endPos = view.state.selection.main.from; - const startPos = lastOpenParen !== -1 ? lastOpenParen + 1 : endPos; + // Find the last comma before the cursor, but after the last open paren + const lastComma = currentText.lastIndexOf(',', endPos - 1); + const startPos = + lastComma > lastOpenParen ? lastComma + 1 : lastOpenParen + 1; + const before = view.state.sliceDoc(startPos, endPos).trim(); + let insertText = ''; + if (before.length > 0) { + // If there's already an argument, insert ", arg" + insertText = `, ${completion.label}`; + } else { + insertText = completion.label; + } view.dispatch({ - changes: { from: startPos, to: endPos, insert: completion.label }, - selection: { anchor: startPos + completion.label.length }, + changes: { from: endPos, insert: insertText }, + selection: { anchor: endPos + insertText.length }, }); }, }),