summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-10-16 13:49:40 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-10-16 21:18:43 +1100
commit87e9d9bdc21ebb38727a04c9df7ef5aadc1eba84 (patch)
treec7d812f28c0ebe6b11407a1dbed0b313859e74e7
parentb6454755caf6b90c935f986558f4f9ad085b1837 (diff)
minor changes
-rw-r--r--pkg/commands/oscommands/os.go4
-rw-r--r--pkg/commands/patch/patch_parser.go21
-rw-r--r--pkg/gui/keybindings.go11
-rw-r--r--pkg/gui/lbl/state.go4
-rw-r--r--pkg/gui/line_by_line_panel.go6
-rw-r--r--pkg/i18n/english.go4
6 files changed, 24 insertions, 26 deletions
diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go
index 5a35b9278..b146d9d8e 100644
--- a/pkg/commands/oscommands/os.go
+++ b/pkg/commands/oscommands/os.go
@@ -546,7 +546,9 @@ func RunLineOutputCmd(cmd *exec.Cmd, onLine func(line string) (bool, error)) err
}
func (c *OSCommand) CopyToClipboard(str string) error {
- c.LogCommand(fmt.Sprintf("Copying '%s' to clipboard", utils.TruncateWithEllipsis(str, 40)), false)
+ escaped := strings.Replace(str, "\n", "\\n", -1)
+ truncated := utils.TruncateWithEllipsis(escaped, 40)
+ c.LogCommand(fmt.Sprintf("Copying '%s' to clipboard", truncated), false)
return clipboard.WriteAll(str)
}
diff --git a/pkg/commands/patch/patch_parser.go b/pkg/commands/patch/patch_parser.go
index 4fed00325..1fefe0748 100644
--- a/pkg/commands/patch/patch_parser.go
+++ b/pkg/commands/patch/patch_parser.go
@@ -194,20 +194,17 @@ func (p *PatchParser) Render(firstLineIndex int, lastLineIndex int, incLineIndic
return result
}
-// RenderLines returns the coloured string of diff part from firstLineIndex to
+// PlainRenderLines returns the non-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 ""
+func (p *PatchParser) PlainRenderLines(firstLineIndex, lastLineIndex int) string {
+ linesToCopy := p.PatchLines[firstLineIndex : lastLineIndex+1]
+
+ renderedLines := make([]string, len(linesToCopy))
+ for index, line := range linesToCopy {
+ renderedLines[index] = line.Content
}
- return result
+
+ return strings.Join(renderedLines, "\n")
}
// GetNextStageableLineIndex takes a line index and returns the line index of the next stageable line
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index 44fee4fce..844a1dc8a 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1304,11 +1304,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleSelectNextHunk,
},
{
- ViewName: "main",
- Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
- Key: gui.getKey(config.Universal.CopyToClipboard),
- Modifier: gocui.ModNone,
- Handler: gui.copySelectedToClipboard,
+ ViewName: "main",
+ Contexts: []string{string(MAIN_PATCH_BUILDING_CONTEXT_KEY), string(MAIN_STAGING_CONTEXT_KEY)},
+ Key: gui.getKey(config.Universal.CopyToClipboard),
+ Modifier: gocui.ModNone,
+ Handler: gui.copySelectedToClipboard,
+ Description: gui.Tr.LcCopySelectedTexToClipboard,
},
{
ViewName: "main",
diff --git a/pkg/gui/lbl/state.go b/pkg/gui/lbl/state.go
index e8014fc1a..8ff7d7e88 100644
--- a/pkg/gui/lbl/state.go
+++ b/pkg/gui/lbl/state.go
@@ -180,9 +180,9 @@ func (s *State) RenderForLineIndices(includedLineIndices []int) string {
return s.patchParser.Render(firstLineIdx, lastLineIdx, includedLineIndices)
}
-func (s *State) RenderSelected() string {
+func (s *State) PlainRenderSelected() string {
firstLineIdx, lastLineIdx := s.SelectedRange()
- return s.patchParser.RenderLines(firstLineIdx, lastLineIdx)
+ return s.patchParser.PlainRenderLines(firstLineIdx, lastLineIdx)
}
func (s *State) SelectBottom() {
diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go
index b366352b0..8c793375b 100644
--- a/pkg/gui/line_by_line_panel.go
+++ b/pkg/gui/line_by_line_panel.go
@@ -2,13 +2,11 @@ package gui
import (
"fmt"
- "strings"
"github.com/go-errors/errors"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/lbl"
- "github.com/jesseduffield/lazygit/pkg/utils"
)
// Currently there are two 'pseudo-panels' that make use of this 'pseudo-panel'.
@@ -90,9 +88,7 @@ func (gui *Gui) handleSelectNextHunk() error {
func (gui *Gui) copySelectedToClipboard() error {
return gui.withLBLActiveCheck(func(state *LblPanelState) error {
-
- colorSelected := state.RenderSelected()
- selected := strings.TrimSpace(utils.Decolorise(colorSelected))
+ selected := state.PlainRenderSelected()
if err := gui.OSCommand.WithSpan(
gui.Tr.Spans.CopySelectedTextToClipboard,
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index eb172ccba..1156cfee7 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -361,6 +361,7 @@ type TranslationSet struct {
LcCopyFileNameToClipboard string
LcCopyCommitFileNameToClipboard string
LcCommitPrefixPatternError string
+ LcCopySelectedTexToClipboard string
NoFilesStagedTitle string
NoFilesStagedPrompt string
BranchNotFoundTitle string
@@ -883,6 +884,7 @@ func englishTranslationSet() TranslationSet {
LcCopyBranchNameToClipboard: "copy branch name to clipboard",
LcCopyFileNameToClipboard: "copy the file name to the clipboard",
LcCopyCommitFileNameToClipboard: "copy the committed file name to the clipboard",
+ LcCopySelectedTexToClipboard: "copy the selected text to the clipboard",
LcCommitPrefixPatternError: "Error in commitPrefix pattern",
NoFilesStagedTitle: "No files staged",
NoFilesStagedPrompt: "You have not staged any files. Commit all files?",
@@ -1000,7 +1002,7 @@ func englishTranslationSet() TranslationSet {
GitFlowFinish: "Git flow finish",
GitFlowStart: "Git Flow start",
CopyToClipboard: "Copy to clipboard",
- CopySelectedTextToClipboard: "Copy Selected Text to clipboard",
+ CopySelectedTextToClipboard: "Copy selected text to clipboard",
RemovePatchFromCommit: "Remove patch from commit",
MovePatchToSelectedCommit: "Move patch to selected commit",
MovePatchIntoIndex: "Move patch into index",