1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

minor changes

This commit is contained in:
Jesse Duffield 2021-10-16 13:49:40 +11:00
parent b6454755ca
commit 87e9d9bdc2
6 changed files with 24 additions and 26 deletions

View File

@ -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)
}

View File

@ -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,
)
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
}
result := strings.Join(renderedLines, "\n")
if strings.TrimSpace(utils.Decolorise(result)) == "" {
return ""
}
return result
return strings.Join(renderedLines, "\n")
}
// GetNextStageableLineIndex takes a line index and returns the line index of the next stageable line

View File

@ -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",

View File

@ -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() {

View File

@ -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,

View File

@ -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",