diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-06-13 11:01:26 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-08-06 13:49:11 +1000 |
commit | 524bf83a4a681408c3fb57818f6968cab632e0ae (patch) | |
tree | 8858b4ee8d4670dcdd1637fe5fedf00ff080c154 /pkg/commands/patch | |
parent | 6dfef08efc5c7f262194c0af35fd777428f33a1a (diff) |
refactor to only have one context per view
Diffstat (limited to 'pkg/commands/patch')
-rw-r--r-- | pkg/commands/patch/patch_manager.go | 2 | ||||
-rw-r--r-- | pkg/commands/patch/patch_parser.go | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go index 4fb6507e6..91adfecb4 100644 --- a/pkg/commands/patch/patch_manager.go +++ b/pkg/commands/patch/patch_manager.go @@ -190,7 +190,7 @@ func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse b parser := NewPatchParser(p.Log, patch) // not passing included lines because we don't want to see them in the secondary panel - return parser.Render(-1, -1, nil) + return parser.Render(false, -1, -1, nil) } func (p *PatchManager) renderEachFilePatch(plain bool) []string { diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go index fa730afe7..90b2ea13e 100644 --- a/pkg/commands/patch/patch_parser.go +++ b/pkg/commands/patch/patch_parser.go @@ -183,7 +183,7 @@ func parsePatch(patch string) ([]int, []int, []*PatchLine) { } // Render returns the coloured string of the diff with any selected lines highlighted -func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndices []int) string { +func (p *PatchParser) Render(isFocused bool, firstLineIndex int, lastLineIndex int, incLineIndices []int) string { contentToDisplay := slices.Some(p.PatchLines, func(line *PatchLine) bool { return line.Content != "" }) @@ -192,7 +192,7 @@ func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndic } renderedLines := slices.MapWithIndex(p.PatchLines, func(patchLine *PatchLine, index int) string { - selected := index >= firstLineIndex && index <= lastLineIndex + selected := isFocused && index >= firstLineIndex && index <= lastLineIndex included := lo.Contains(incLineIndices, index) return patchLine.render(selected, included) }) @@ -202,12 +202,18 @@ func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndic return result } -// PlainRenderLines returns the non-coloured string of diff part from firstLineIndex to +func (p *PatchParser) RenderPlain() string { + return renderLinesPlain(p.PatchLines) +} + +// RenderLinesPlain returns the non-coloured string of diff part from firstLineIndex to // lastLineIndex -func (p *PatchParser) PlainRenderLines(firstLineIndex, lastLineIndex int) string { - linesToCopy := p.PatchLines[firstLineIndex : lastLineIndex+1] +func (p *PatchParser) RenderLinesPlain(firstLineIndex, lastLineIndex int) string { + return renderLinesPlain(p.PatchLines[firstLineIndex : lastLineIndex+1]) +} - renderedLines := slices.Map(linesToCopy, func(line *PatchLine) string { +func renderLinesPlain(lines []*PatchLine) string { + renderedLines := slices.Map(lines, func(line *PatchLine) string { return line.Content }) |