Skip to content

Commit 42bbe96

Browse files
committed
Render only + and - lines as included in a patch
It is confusing to get header lines, hunk headers, or context lines rendered as being included in a custom patch, when including these makes no difference to the patch. This is only a visual change; internally, we still record these non-patch lines as being included in the patch. It doesn't matter though; you can press space on a header line and nothing happens. It would probably be cleaner to only record + and - lines in the includedLines array, but that would be a bit more work, and doesn't seem worth it.
1 parent a8e9859 commit 42bbe96

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

pkg/commands/patch/format.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,22 @@ func (self *patchPresenter) format() string {
7272

7373
lineIdx++
7474
}
75-
appendFormattedLine := func(line string, style style.TextStyle) {
76-
formattedLine := self.formatLine(
77-
line,
78-
style,
79-
lineIdx,
80-
)
81-
82-
appendLine(formattedLine)
83-
}
8475

8576
for _, line := range self.patch.header {
86-
appendFormattedLine(line, theme.DefaultTextColor.SetBold())
77+
// always passing false for 'included' here because header lines are not part of the patch
78+
appendLine(self.formatLineAux(line, theme.DefaultTextColor.SetBold(), false))
8779
}
8880

8981
for _, hunk := range self.patch.hunks {
9082
appendLine(
91-
self.formatLine(
83+
self.formatLineAux(
9284
hunk.formatHeaderStart(),
9385
style.FgCyan,
94-
lineIdx,
86+
false,
9587
) +
9688
// we're splitting the line into two parts: the diff header and the context
97-
// We explicitly pass 'included' as false here so that we're only tagging the
98-
// first half of the line as included if the line is indeed included.
89+
// We explicitly pass 'included' as false for both because these are not part
90+
// of the actual patch
9991
self.formatLineAux(
10092
hunk.headerContext,
10193
theme.DefaultTextColor,
@@ -104,7 +96,12 @@ func (self *patchPresenter) format() string {
10496
)
10597

10698
for _, line := range hunk.bodyLines {
107-
appendFormattedLine(line.Content, self.patchLineStyle(line))
99+
style := self.patchLineStyle(line)
100+
if line.isChange() {
101+
appendLine(self.formatLine(line.Content, style, lineIdx))
102+
} else {
103+
appendLine(self.formatLineAux(line.Content, style, false))
104+
}
108105
}
109106
}
110107

0 commit comments

Comments
 (0)