Make lastCutTime actually work

The CutLine action has a feature: if we execute it multiple times to cut
multiple lines, new cut lines are added to the previously cut lines in
the clipboard instead of replacing the clipboard, unless those
previously cut lines have been already pasted or the last cut was more
than 10 seconds ago. This last bit doesn't really work: newly cut lines
are appended to the clipboard regardless of when was the last cut.
So fix it.
This commit is contained in:
Dmytro Maluka
2024-06-09 12:07:07 +02:00
parent 8bc67569f9
commit 52ed4315ff

View File

@@ -1201,7 +1201,7 @@ func (h *BufPane) CutLine() bool {
if !h.Cursor.HasSelection() { if !h.Cursor.HasSelection() {
return false return false
} }
if h.freshClip { if h.freshClip && time.Since(h.lastCutTime) < 10*time.Second {
if h.Cursor.HasSelection() { if h.Cursor.HasSelection() {
if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil { if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil {
InfoBar.Error(err) InfoBar.Error(err)
@@ -1209,7 +1209,7 @@ func (h *BufPane) CutLine() bool {
clipboard.WriteMulti(clip+string(h.Cursor.GetSelection()), clipboard.ClipboardReg, h.Cursor.Num, h.Buf.NumCursors()) clipboard.WriteMulti(clip+string(h.Cursor.GetSelection()), clipboard.ClipboardReg, h.Cursor.Num, h.Buf.NumCursors())
} }
} }
} else if time.Since(h.lastCutTime)/time.Second > 10*time.Second || !h.freshClip { } else {
h.Copy() h.Copy()
} }
h.freshClip = true h.freshClip = true