1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02:00

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.
This commit is contained in:
Stefan Haller
2025-07-01 17:06:12 +02:00
parent a8e98593ea
commit 42bbe965fa

View File

@ -72,30 +72,22 @@ func (self *patchPresenter) format() string {
lineIdx++
}
appendFormattedLine := func(line string, style style.TextStyle) {
formattedLine := self.formatLine(
line,
style,
lineIdx,
)
appendLine(formattedLine)
}
for _, line := range self.patch.header {
appendFormattedLine(line, theme.DefaultTextColor.SetBold())
// always passing false for 'included' here because header lines are not part of the patch
appendLine(self.formatLineAux(line, theme.DefaultTextColor.SetBold(), false))
}
for _, hunk := range self.patch.hunks {
appendLine(
self.formatLine(
self.formatLineAux(
hunk.formatHeaderStart(),
style.FgCyan,
lineIdx,
false,
) +
// we're splitting the line into two parts: the diff header and the context
// We explicitly pass 'included' as false here so that we're only tagging the
// first half of the line as included if the line is indeed included.
// We explicitly pass 'included' as false for both because these are not part
// of the actual patch
self.formatLineAux(
hunk.headerContext,
theme.DefaultTextColor,
@ -104,7 +96,12 @@ func (self *patchPresenter) format() string {
)
for _, line := range hunk.bodyLines {
appendFormattedLine(line.Content, self.patchLineStyle(line))
style := self.patchLineStyle(line)
if line.isChange() {
appendLine(self.formatLine(line.Content, style, lineIdx))
} else {
appendLine(self.formatLineAux(line.Content, style, false))
}
}
}