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 / body / plan / hunk-window-of.ts
32 lines · 867 BRaw
1import Git from '../../../git'
2import type { HunkSegment, WindowCut } from '../types'
3
4/**
5 * The part of a hunk the window shows: from the line holding its first
6 * shown row (hunkAfter renumbers) to the last that starts in the room left.
7 *
8 * @param segment the hunk and the rows each of its lines takes
9 * @param cut the rows hidden above the window and the rows it has left
10 * @returns the hunk's shown lines
11 */
12export function hunkWindowOf(segment: HunkSegment, cut: WindowCut): Git.Hunk {
13 let passed = 0
14 let first = 0
15 let shown = 0
16 let last = 0
17
18 for (const rows of segment.lineRows) {
19 if (passed + rows <= cut.skip) {
20 first += 1
21 } else if (shown < cut.take) {
22 shown += rows
23 last += 1
24 }
25
26 passed += rows
27 }
28
29 const tail = Git.hunkAfter(segment.hunk, first)
30
31 return { ...tail, lines: tail.lines.slice(0, last) }
32}