diff options
author | Hrishikesh Hiraskar <hrishi@enterpret.com> | 2021-10-02 13:20:26 +0530 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-16 21:18:43 +1100 |
commit | b6454755caf6b90c935f986558f4f9ad085b1837 (patch) | |
tree | 65704a5fc6436390cf8dbe54428936edb0d9c6ff /pkg/gui | |
parent | 36210840962bb448208b6cc628319f994c392075 (diff) |
copy selected text to clipboard
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/keybindings.go | 7 | ||||
-rw-r--r-- | pkg/gui/lbl/state.go | 5 | ||||
-rw-r--r-- | pkg/gui/line_by_line_panel.go | 18 |
3 files changed, 30 insertions, 0 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 0280d6fd1..44fee4fce 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1304,6 +1304,13 @@ 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_STAGING_CONTEXT_KEY)}, Key: gui.getKey(config.Universal.Edit), diff --git a/pkg/gui/lbl/state.go b/pkg/gui/lbl/state.go index 8ae828923..e8014fc1a 100644 --- a/pkg/gui/lbl/state.go +++ b/pkg/gui/lbl/state.go @@ -180,6 +180,11 @@ func (s *State) RenderForLineIndices(includedLineIndices []int) string { return s.patchParser.Render(firstLineIdx, lastLineIdx, includedLineIndices) } +func (s *State) RenderSelected() string { + firstLineIdx, lastLineIdx := s.SelectedRange() + return s.patchParser.RenderLines(firstLineIdx, lastLineIdx) +} + func (s *State) SelectBottom() { s.SetLineSelectMode() s.SelectLine(len(s.patchParser.PatchLines) - 1) diff --git a/pkg/gui/line_by_line_panel.go b/pkg/gui/line_by_line_panel.go index 8121b6ed3..b366352b0 100644 --- a/pkg/gui/line_by_line_panel.go +++ b/pkg/gui/line_by_line_panel.go @@ -2,11 +2,13 @@ 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'. @@ -86,6 +88,22 @@ 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)) + + if err := gui.OSCommand.WithSpan( + gui.Tr.Spans.CopySelectedTextToClipboard, + ).CopyToClipboard(selected); err != nil { + return gui.surfaceError(err) + } + + return nil + }) +} + func (gui *Gui) refreshAndFocusLblPanel(state *LblPanelState) error { if err := gui.refreshMainViewForLineByLine(state); err != nil { return err |