From 5d3e4fc3d95c2077f0e546a39b92a73c2f9eccba Mon Sep 17 00:00:00 2001 From: Jeff Warner Date: Wed, 29 Apr 2020 21:06:54 -0700 Subject: [PATCH] Adds CopyLine action, the new default action for CtrlC if cursor has no selection --- internal/action/actions.go | 19 +++++++++++++++++++ internal/action/bufpane.go | 2 ++ internal/action/defaults_darwin.go | 2 +- internal/action/defaults_other.go | 2 +- runtime/help/keybindings.md | 3 ++- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index fd363281..79ce8cf3 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -930,6 +930,25 @@ func (h *BufPane) Copy() bool { return true } +// Copy the current line to the clipboard +func (h *BufPane) CopyLine() bool { + if h.Cursor.HasSelection() { + return false + } else { + h.Cursor.SelectLine() + h.Cursor.CopySelection("clipboard") + h.freshClip = true + if clipboard.Unsupported { + InfoBar.Message("Copied line (install xclip for external clipboard)") + } else { + InfoBar.Message("Copied line") + } + } + h.Cursor.Deselect(true) + h.Relocate() + return true +} + // CutLine cuts the current line to the clipboard func (h *BufPane) CutLine() bool { h.Cursor.SelectLine() diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 31e53e32..e60ead55 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -558,6 +558,7 @@ var BufKeyActions = map[string]BufKeyAction{ "Undo": (*BufPane).Undo, "Redo": (*BufPane).Redo, "Copy": (*BufPane).Copy, + "CopyLine": (*BufPane).CopyLine, "Cut": (*BufPane).Cut, "CutLine": (*BufPane).CutLine, "DuplicateLine": (*BufPane).DuplicateLine, @@ -669,6 +670,7 @@ var MultiActions = map[string]bool{ "InsertTab": true, "FindNext": true, "FindPrevious": true, + "CopyLine": true, "Cut": true, "CutLine": true, "DuplicateLine": true, diff --git a/internal/action/defaults_darwin.go b/internal/action/defaults_darwin.go index 89f03290..b80e07d7 100644 --- a/internal/action/defaults_darwin.go +++ b/internal/action/defaults_darwin.go @@ -43,7 +43,7 @@ func DefaultBindings() map[string]string { "CtrlP": "FindPrevious", "CtrlZ": "Undo", "CtrlY": "Redo", - "CtrlC": "Copy", + "CtrlC": "CopyLine|Copy", "CtrlX": "Cut", "CtrlK": "CutLine", "CtrlD": "DuplicateLine", diff --git a/internal/action/defaults_other.go b/internal/action/defaults_other.go index e63c1ee1..fca4a8d7 100644 --- a/internal/action/defaults_other.go +++ b/internal/action/defaults_other.go @@ -45,7 +45,7 @@ func DefaultBindings() map[string]string { "CtrlP": "FindPrevious", "CtrlZ": "Undo", "CtrlY": "Redo", - "CtrlC": "Copy", + "CtrlC": "CopyLine|Copy", "CtrlX": "Cut", "CtrlK": "CutLine", "CtrlD": "DuplicateLine", diff --git a/runtime/help/keybindings.md b/runtime/help/keybindings.md index f303e8a2..b8f67064 100644 --- a/runtime/help/keybindings.md +++ b/runtime/help/keybindings.md @@ -190,6 +190,7 @@ FindPrevious Undo Redo Copy +CopyLine Cut CutLine DuplicateLine @@ -455,7 +456,7 @@ conventions for text editing defaults. "CtrlP": "FindPrevious", "CtrlZ": "Undo", "CtrlY": "Redo", - "CtrlC": "Copy", + "CtrlC": "CopyLine|Copy", "CtrlX": "Cut", "CtrlK": "CutLine", "CtrlD": "DuplicateLine",