Skip to content

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.

TypeScript
698 B
Raw Blame
import type Git from '../../../../git'
import { hunkHeaderOf } from '../../hunk-header-of'

/**
 * A hunk's first line cut so that it alone, under its header, fits the
 * room: its marker kept, no surrogate pair split.
 *
 * @param hunk the hunk, its first line too long for a sub-hunk of its own
 * @param maxChars the room the one-line sub-hunk's text fits
 * @returns the cut line
 */
export function firstLineCut(hunk: Git.Hunk, maxChars: number) {
  const [first = ''] = hunk.lines

  const kept = first.slice(
    0,
    Math.max(
      1,
      maxChars - 1 - hunkHeaderOf({ ...hunk, lines: [first] }).length,
    ),
  )

  return /[\uD800-\uDBFF]$/u.test(kept) ? kept.slice(0, -1) : kept
}