Remap Pierre token hues that collide with diff add/remove semantics into theme-safe syntax colors.
(color: string | undefined, theme: AppTheme)
| 330 | |
| 331 | /** Remap Pierre token hues that collide with diff add/remove semantics into theme-safe syntax colors. */ |
| 332 | function normalizeHighlightedColor(color: string | undefined, theme: AppTheme) { |
| 333 | if (!color) { |
| 334 | return color; |
| 335 | } |
| 336 | |
| 337 | const themeKey = themeRenderCacheKey(theme); |
| 338 | let cacheForTheme = normalizedColorCache.get(themeKey); |
| 339 | if (!cacheForTheme) { |
| 340 | cacheForTheme = new Map<string, string>(); |
| 341 | normalizedColorCache.set(themeKey, cacheForTheme); |
| 342 | } |
| 343 | |
| 344 | const cached = cacheForTheme.get(color); |
| 345 | if (cached) { |
| 346 | return cached; |
| 347 | } |
| 348 | |
| 349 | const normalized = color.trim().toLowerCase(); |
| 350 | const reserved = |
| 351 | RESERVED_PIERRE_TOKEN_COLORS[theme.appearance][ |
| 352 | normalized as keyof (typeof RESERVED_PIERRE_TOKEN_COLORS)[typeof theme.appearance] |
| 353 | ]; |
| 354 | const resolvedColor = reserved |
| 355 | ? (theme.syntaxColors[reserved] ?? |
| 356 | (reserved === "operator" ? theme.syntaxColors.punctuation : theme.syntaxColors.default)) |
| 357 | : color; |
| 358 | cacheForTheme.set(color, resolvedColor); |
| 359 | return resolvedColor; |
| 360 | } |
| 361 | |
| 362 | /** Append a span while coalescing adjacent runs with identical colors. */ |
| 363 | function mergeSpan(target: RenderSpan[], next: RenderSpan) { |
no test coverage detected