@@ -132,21 +132,11 @@ func (dv *DiffView) String() string {
132132 var b strings.Builder
133133
134134 for i, h := range dv.unified.Hunks {
135− beforeShownLines, afterShownLines := dv.hunkShownLines(i)
136−
137135 if dv.lineNumbers {
138136 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", beforeNumDigits)))
139137 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", afterNumDigits)))
140138 }
141− b.WriteString(dv.style.DividerLine.Code.Width(codeWidth + leadingSymbolsSize).Render(
142− fmt.Sprintf(
143− " @@ -%d,%d +%d,%d @@",
144− h.FromLine,
145− beforeShownLines,
146− h.ToLine,
147− afterShownLines,
148− ),
149− ))
139+ b.WriteString(dv.style.DividerLine.Code.Width(codeWidth + leadingSymbolsSize).Render(dv.hunkLineFor(i)))
150140 b.WriteRune('\n')
151141
152142 beforeLine := h.FromLine
@@ -217,6 +207,19 @@ func (dv *DiffView) lineNumberDigits() (maxBefore, maxAfter int) {
217207 return
218208}
219209
210+func (dv *DiffView) hunkLineFor(i int) string {
211+ h := dv.unified.Hunks[i]
212+ beforeShownLines, afterShownLines := dv.hunkShownLines(i)
213+
214+ return fmt.Sprintf(
215+ " @@ -%d,%d +%d,%d @@ ",
216+ h.FromLine,
217+ beforeShownLines,
218+ h.ToLine,
219+ afterShownLines,
220+ )
221+}
222+
220223// hunkShownLines calculates the number of lines shown in a hunk for both before
221224// and after versions.
222225func (dv *DiffView) hunkShownLines(i int) (before, after int) {
@@ -239,11 +242,13 @@ func (dv *DiffView) detectWidth() {
239242 return
240243 }
241244
242− for _, h := range dv.unified.Hunks {
245+ for i, h := range dv.unified.Hunks {
246+ shownLines := ansi.StringWidth(dv.hunkLineFor(i))
247+
243248 for _, l := range h.Lines {
244249 lineWidth := ansi.StringWidth(strings.TrimSuffix(l.Content, "\n"))
245250 lineWidth += leadingSymbolsSize
246− dv.width = max(dv.width, lineWidth)
251+ dv.width = max(dv.width, lineWidth, shownLines)
247252 }
248253 }
249254}