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:
@ -72,30 +72,22 @@ func (self *patchPresenter) format() string {
|
|||||||
|
|
||||||
lineIdx++
|
lineIdx++
|
||||||
}
|
}
|
||||||
appendFormattedLine := func(line string, style style.TextStyle) {
|
|
||||||
formattedLine := self.formatLine(
|
|
||||||
line,
|
|
||||||
style,
|
|
||||||
lineIdx,
|
|
||||||
)
|
|
||||||
|
|
||||||
appendLine(formattedLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, line := range self.patch.header {
|
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 {
|
for _, hunk := range self.patch.hunks {
|
||||||
appendLine(
|
appendLine(
|
||||||
self.formatLine(
|
self.formatLineAux(
|
||||||
hunk.formatHeaderStart(),
|
hunk.formatHeaderStart(),
|
||||||
style.FgCyan,
|
style.FgCyan,
|
||||||
lineIdx,
|
false,
|
||||||
) +
|
) +
|
||||||
// we're splitting the line into two parts: the diff header and the context
|
// 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
|
// We explicitly pass 'included' as false for both because these are not part
|
||||||
// first half of the line as included if the line is indeed included.
|
// of the actual patch
|
||||||
self.formatLineAux(
|
self.formatLineAux(
|
||||||
hunk.headerContext,
|
hunk.headerContext,
|
||||||
theme.DefaultTextColor,
|
theme.DefaultTextColor,
|
||||||
@ -104,7 +96,12 @@ func (self *patchPresenter) format() string {
|
|||||||
)
|
)
|
||||||
|
|
||||||
for _, line := range hunk.bodyLines {
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user