Skip to content

Commit d39e9f2

Browse files
committed
fix(diff): resolve a code field's language from either version
A removed block's language exists only in the base version, and an empty saved language short-circuited the lookup, so both fell back to JavaScript or to no highlighting. The language now comes from the target values, then the base values, then the field default, through a Map so only the listed languages can match.
1 parent 5f9453a commit d39e9f2

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/components/workflow-diff/components/change-list

‎apps/sim/app/workspace/[workspaceId]/w/components/workflow-diff/components/change-list/field-change-row.tsx‎

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,33 @@ import type { SubBlockConfig } from '@/blocks/types'
2626
import { formatParameterLabel } from '@/tools/params'
2727

2828
/** Code languages blocks offer, as the highlighter names them. */
29-
const CODE_DIFF_LANGUAGES: Record<string, string> = {
30-
javascript: 'javascript',
31-
typescript: 'typescript',
32-
python: 'python',
33-
shell: 'bash',
34-
json: 'json',
35-
}
29+
const CODE_DIFF_LANGUAGES = new Map([
30+
['javascript', 'javascript'],
31+
['typescript', 'typescript'],
32+
['python', 'python'],
33+
['shell', 'bash'],
34+
['json', 'json'],
35+
])
3636

3737
/**
38-
* The syntax a text diff highlights as: JSON for structured values, a code field's language
39-
* (the block's own `language` setting first, as the editor does), and plain text for prose.
38+
* The syntax a text diff highlights as: JSON for structured values, plain text for prose, and
39+
* for code the first language that names one the highlighter knows: the block's `language`
40+
* setting after the change, then before it (a removed block has only that), then the field's
41+
* own default.
4042
*/
4143
function diffLanguage(
4244
config: SubBlockConfig | undefined,
4345
kind: ValueKind,
44-
values: Record<string, unknown>
46+
targetValues: Record<string, unknown>,
47+
baseValues: Record<string, unknown>
4548
): string {
4649
if (kind === 'json') return 'json'
4750
if (config?.type !== 'code') return 'text'
48-
const selected = typeof values.language === 'string' ? values.language : undefined
49-
return (
50-
(selected && CODE_DIFF_LANGUAGES[selected]) ??
51-
CODE_DIFF_LANGUAGES[config.language ?? 'javascript'] ??
52-
'javascript'
53-
)
51+
for (const value of [targetValues.language, baseValues.language, config.language]) {
52+
const language = typeof value === 'string' ? CODE_DIFF_LANGUAGES.get(value) : undefined
53+
if (language) return language
54+
}
55+
return 'javascript'
5456
}
5557

5658
interface FieldChangeRowProps {
@@ -150,7 +152,7 @@ export function FieldChangeRow({
150152
<TextDiff
151153
oldText={oldText}
152154
newText={newText}
153-
language={diffLanguage(config, kind, targetValues)}
155+
language={diffLanguage(config, kind, targetValues, baseValues)}
154156
/>
155157
)}
156158
{scalar &&

0 commit comments

Comments
 (0)