spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / views / layout / sanitize-line / sanitize-line.ts
17 lines · 651 BRaw
1import { TAB_WIDTH } from '../tab-width'
2
3/**
4 * A diff line made safe to measure and draw: tabs become spaces, and every
5 * control, format and default-ignorable character is dropped.
6 *
7 * The render tree refuses control characters; the rest (bidi overrides,
8 * zero-width spaces and joiners, variation selectors, the soft hyphen)
9 * draw as nothing, so nothing invisible can reorder, hide or pad a line.
10 *
11 * @param text one line of file content
12 * @returns the drawable line
13 */
14export const sanitizeLine = (text: string) =>
15 text
16 .replaceAll('\t', ' '.repeat(TAB_WIDTH))
17 .replace(/[\p{Cc}\p{Cf}\p{Default_Ignorable_Code_Point}]/gu, '')