From 04143c7a890d992fb1fcd0733c18f5e7c3e2ba79 Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Sun, 9 Jun 2024 14:58:05 +0200 Subject: [PATCH] Make Cut, Copy, CopyLine don't mess with CutLine's multi line cuts Weird behavior is observed e.g. if we cut some lines with CutLine, then copy some selection with Copy, then cut some other lines with CutLine, and then paste. The pasted cliboard contains not just the lines that were cut at the last step, but also the selection that was copied before that. Fix that by resetting the CutLine's repeated line cuts whenever we copy anything to the clipboard via any other action (Cut, Copy or CopyLine). --- internal/action/actions.go | 8 ++++---- internal/action/bufpane.go | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 9e9cb8b8..89821beb 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1188,7 +1188,7 @@ func (h *BufPane) Copy() bool { return false } h.Cursor.CopySelection(clipboard.ClipboardReg) - h.freshClip = true + h.freshClip = false InfoBar.Message("Copied selection") h.Relocate() return true @@ -1206,7 +1206,7 @@ func (h *BufPane) CopyLine() bool { return false } h.Cursor.CopySelection(clipboard.ClipboardReg) - h.freshClip = true + h.freshClip = false if nlines > 1 { InfoBar.Message(fmt.Sprintf("Copied %d lines", nlines)) } else { @@ -1228,7 +1228,7 @@ func (h *BufPane) Cut() bool { h.Cursor.CopySelection(clipboard.ClipboardReg) h.Cursor.DeleteSelection() h.Cursor.ResetSelection() - h.freshClip = true + h.freshClip = false InfoBar.Message("Cut selection") h.Relocate() @@ -1251,7 +1251,7 @@ func (h *BufPane) CutLine() bool { totalLines = strings.Count(clip, "\n") + nlines } } else { - h.Copy() + h.Cursor.CopySelection(clipboard.ClipboardReg) } h.freshClip = true h.lastCutTime = time.Now() diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 7b348b79..6a9e0e09 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -235,7 +235,8 @@ type BufPane struct { // It is used for clearing the clipboard to replace it with fresh cut lines. lastCutTime time.Time - // freshClip returns true if the clipboard has never been pasted. + // freshClip returns true if one or more lines have been cut to the clipboard + // and have never been pasted yet. freshClip bool // Was the last mouse event actually a double click?