MCPcopy Create free account
hub / github.com/modem-dev/hunk / normalizeHighlightedColor

Function normalizeHighlightedColor

src/ui/diff/pierre.ts:332–360  ·  view source on GitHub ↗

Remap Pierre token hues that collide with diff add/remove semantics into theme-safe syntax colors.

(color: string | undefined, theme: AppTheme)

Source from the content-addressed store, hash-verified

330
331/** Remap Pierre token hues that collide with diff add/remove semantics into theme-safe syntax colors. */
332function 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. */
363function mergeSpan(target: RenderSpan[], next: RenderSpan) {

Callers 1

visitFunction · 0.85

Calls 1

themeRenderCacheKeyFunction · 0.85

Tested by

no test coverage detected