From 4f3fa9000ae19c624d8a2d423ff237c0d8dcee89 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Wed, 5 Feb 2025 11:59:53 -0800 Subject: [PATCH] Fixed small bug with envvar dropdown text replacement that resulted in extra '}}' --- components/ui/env-var-dropdown.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/ui/env-var-dropdown.tsx b/components/ui/env-var-dropdown.tsx index 30eceab1c6..5caa265d04 100644 --- a/components/ui/env-var-dropdown.tsx +++ b/components/ui/env-var-dropdown.tsx @@ -39,12 +39,19 @@ export const EnvVarDropdown: React.FC = ({ const textBeforeCursor = inputValue.slice(0, cursorPosition) const textAfterCursor = inputValue.slice(cursorPosition) - // Find the position of the last '{{' before cursor + // Find the start of the env var syntax (last '{{' before cursor) const lastOpenBraces = textBeforeCursor.lastIndexOf('{{') - if (lastOpenBraces === -1) return - const newValue = - textBeforeCursor.slice(0, lastOpenBraces) + '{{' + envVar + '}}' + textAfterCursor + // Get the text before the env var syntax + const startText = + lastOpenBraces !== -1 ? textBeforeCursor.slice(0, lastOpenBraces) : textBeforeCursor + + // Find the end of any existing env var syntax after cursor + const closeIndex = textAfterCursor.indexOf('}}') + const endText = closeIndex !== -1 ? textAfterCursor.slice(closeIndex + 2) : textAfterCursor + + // Construct the new value with proper env var syntax + const newValue = startText + '{{' + envVar + '}}' + endText onSelect(newValue) onClose?.()