From b6454755caf6b90c935f986558f4f9ad085b1837 Mon Sep 17 00:00:00 2001 From: Hrishikesh Hiraskar Date: Sat, 2 Oct 2021 13:20:26 +0530 Subject: copy selected text to clipboard --- pkg/commands/patch/patch_parser.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'pkg/commands') diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go index 4fb8eb68b..4fed00325 100644 --- a/pkg/commands/patch/patch_parser.go +++ b/pkg/commands/patch/patch_parser.go @@ -194,6 +194,22 @@ func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndic return result } +// RenderLines returns the coloured string of diff part from firstLineIndex to +// lastLineIndex +func (p *PatchParser) RenderLines(firstLineIndex, lastLineIndex int) string { + renderedLines := make([]string, lastLineIndex-firstLineIndex+1) + for index := firstLineIndex; index <= lastLineIndex; index++ { + renderedLines[index-firstLineIndex] = p.PatchLines[index].render( + false, false, + ) + } + result := strings.Join(renderedLines, "\n") + if strings.TrimSpace(utils.Decolorise(result)) == "" { + return "" + } + return result +} + // GetNextStageableLineIndex takes a line index and returns the line index of the next stageable line // note this will actually include the current index if it is stageable func (p *PatchParser) GetNextStageableLineIndex(currentIndex int) int { -- cgit v1.2.3