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 / detail / sub-hunks-of / first-line-cut / first-line-cut.ts
23 lines · 697 BRaw
1import type Git from '../../../../git'
2import { hunkHeaderOf } from '../../hunk-header-of'
3
4/**
5 * A hunk's first line cut so that it alone, under its header, fits the
6 * room: its marker kept, no surrogate pair split.
7 *
8 * @param hunk the hunk, its first line too long for a sub-hunk of its own
9 * @param maxChars the room the one-line sub-hunk's text fits
10 * @returns the cut line
11 */
12export function firstLineCut(hunk: Git.Hunk, maxChars: number) {
13 const [first = ''] = hunk.lines
14 const kept = first.slice(
15 0,
16 Math.max(
17 1,
18 maxChars - 1 - hunkHeaderOf({ ...hunk, lines: [first] }).length,
19 ),
20 )
21
22 return /[\uD800-\uDBFF]$/u.test(kept) ? kept.slice(0, -1) : kept
23}