Skip to content

Commit bc8947c

Browse files
authored
fix(condition): treat condition input the same as the code subblock (#2006)
1 parent f1111ec commit bc8947c

File tree

1 file changed

+33
-17
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/condition-input

1 file changed

+33
-17
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/condition-input/condition-input.tsx

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -864,21 +864,33 @@ export function ConditionInput({
864864
placeholder: string
865865
original: string
866866
type: 'var' | 'env'
867+
shouldHighlight: boolean
867868
}[] = []
868869
let processedCode = codeToHighlight
869870

870871
// Replace environment variables with placeholders
871872
processedCode = processedCode.replace(/\{\{([^}]+)\}\}/g, (match) => {
872873
const placeholder = `__ENV_VAR_${placeholders.length}__`
873-
placeholders.push({ placeholder, original: match, type: 'env' })
874+
placeholders.push({
875+
placeholder,
876+
original: match,
877+
type: 'env',
878+
shouldHighlight: true,
879+
})
874880
return placeholder
875881
})
876882

877883
// Replace variable references with placeholders
878884
processedCode = processedCode.replace(/<([^>]+)>/g, (match) => {
879-
if (shouldHighlightReference(match)) {
885+
const shouldHighlight = shouldHighlightReference(match)
886+
if (shouldHighlight) {
880887
const placeholder = `__VAR_REF_${placeholders.length}__`
881-
placeholders.push({ placeholder, original: match, type: 'var' })
888+
placeholders.push({
889+
placeholder,
890+
original: match,
891+
type: 'var',
892+
shouldHighlight: true,
893+
})
882894
return placeholder
883895
}
884896
return match
@@ -892,21 +904,25 @@ export function ConditionInput({
892904
)
893905

894906
// Restore and highlight the placeholders
895-
placeholders.forEach(({ placeholder, original, type }) => {
896-
if (type === 'env') {
897-
highlightedCode = highlightedCode.replace(
898-
placeholder,
899-
`<span class="text-blue-500">${original}</span>`
900-
)
901-
} else if (type === 'var') {
902-
// Escape the < and > for display
903-
const escaped = original.replace(/</g, '&lt;').replace(/>/g, '&gt;')
904-
highlightedCode = highlightedCode.replace(
905-
placeholder,
906-
`<span class="text-blue-500">${escaped}</span>`
907-
)
907+
placeholders.forEach(
908+
({ placeholder, original, type, shouldHighlight }) => {
909+
if (!shouldHighlight) return
910+
911+
if (type === 'env') {
912+
highlightedCode = highlightedCode.replace(
913+
placeholder,
914+
`<span class="text-blue-500">${original}</span>`
915+
)
916+
} else if (type === 'var') {
917+
// Escape the < and > for display
918+
const escaped = original.replace(/</g, '&lt;').replace(/>/g, '&gt;')
919+
highlightedCode = highlightedCode.replace(
920+
placeholder,
921+
`<span class="text-blue-500">${escaped}</span>`
922+
)
923+
}
908924
}
909-
})
925+
)
910926

911927
return highlightedCode
912928
}}

0 commit comments

Comments
 (0)