X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=internal%2Faction%2Factions.go;h=5d7b31e0238b9f0dd70ab9ca2a4515791a2eefea;hb=f143418267df07c0f9424e02cc942edfdf3f450f;hp=184a57e0820feedc1bc84b66b508e25ceb91a106;hpb=3ddb2ee31639dfb7ce875a882c8afb897901e8dd;p=micro.git diff --git a/internal/action/actions.go b/internal/action/actions.go index 184a57e0..5d7b31e0 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -7,8 +7,8 @@ import ( "time" shellquote "github.com/kballard/go-shellquote" - "github.com/zyedidia/clipboard" "github.com/zyedidia/micro/v2/internal/buffer" + "github.com/zyedidia/micro/v2/internal/clipboard" "github.com/zyedidia/micro/v2/internal/config" "github.com/zyedidia/micro/v2/internal/screen" "github.com/zyedidia/micro/v2/internal/shell" @@ -59,7 +59,7 @@ func (h *BufPane) MousePress(e *tcell.EventMouse) bool { h.doubleClick = false h.Cursor.SelectLine() - h.Cursor.CopySelection("primary") + h.Cursor.CopySelection(clipboard.PrimaryReg) } else { // Double click h.lastClickTime = time.Now() @@ -68,7 +68,7 @@ func (h *BufPane) MousePress(e *tcell.EventMouse) bool { h.tripleClick = false h.Cursor.SelectWord() - h.Cursor.CopySelection("primary") + h.Cursor.CopySelection(clipboard.PrimaryReg) } } else { h.doubleClick = false @@ -961,13 +961,9 @@ func (h *BufPane) Redo() bool { // Copy the selection to the system clipboard func (h *BufPane) Copy() bool { if h.Cursor.HasSelection() { - h.Cursor.CopySelection("clipboard") + h.Cursor.CopySelection(clipboard.ClipboardReg) h.freshClip = true - if clipboard.Unsupported { - InfoBar.Message("Copied selection (install xclip for external clipboard)") - } else { - InfoBar.Message("Copied selection") - } + InfoBar.Message("Copied selection") } h.Relocate() return true @@ -979,13 +975,9 @@ func (h *BufPane) CopyLine() bool { return false } else { h.Cursor.SelectLine() - h.Cursor.CopySelection("clipboard") + h.Cursor.CopySelection(clipboard.ClipboardReg) h.freshClip = true - if clipboard.Unsupported { - InfoBar.Message("Copied line (install xclip for external clipboard)") - } else { - InfoBar.Message("Copied line") - } + InfoBar.Message("Copied line") } h.Cursor.Deselect(true) h.Relocate() @@ -1000,10 +992,10 @@ func (h *BufPane) CutLine() bool { } if h.freshClip == true { if h.Cursor.HasSelection() { - if clip, err := clipboard.ReadAll("clipboard"); err != nil { - // messenger.Error(err) + if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil { + InfoBar.Error(err) } else { - clipboard.WriteAll(clip+string(h.Cursor.GetSelection()), "clipboard") + clipboard.Write(clip+string(h.Cursor.GetSelection()), clipboard.ClipboardReg) } } } else if time.Since(h.lastCutTime)/time.Second > 10*time.Second || h.freshClip == false { @@ -1021,7 +1013,7 @@ func (h *BufPane) CutLine() bool { // Cut the selection to the system clipboard func (h *BufPane) Cut() bool { if h.Cursor.HasSelection() { - h.Cursor.CopySelection("clipboard") + h.Cursor.CopySelection(clipboard.ClipboardReg) h.Cursor.DeleteSelection() h.Cursor.ResetSelection() h.freshClip = true @@ -1147,7 +1139,10 @@ func (h *BufPane) MoveLinesDown() bool { // Paste whatever is in the system clipboard into the buffer // Delete and paste if the user has a selection func (h *BufPane) Paste() bool { - clip, _ := clipboard.ReadAll("clipboard") + clip, err := clipboard.Read(clipboard.ClipboardReg) + if err != nil { + InfoBar.Error(err) + } h.paste(clip) h.Relocate() return true @@ -1155,7 +1150,10 @@ func (h *BufPane) Paste() bool { // PastePrimary pastes from the primary clipboard (only use on linux) func (h *BufPane) PastePrimary() bool { - clip, _ := clipboard.ReadAll("primary") + clip, err := clipboard.Read(clipboard.PrimaryReg) + if err != nil { + InfoBar.Error(err) + } h.paste(clip) h.Relocate() return true @@ -1177,11 +1175,7 @@ func (h *BufPane) paste(clip string) { h.Buf.Insert(h.Cursor.Loc, clip) // h.Cursor.Loc = h.Cursor.Loc.Move(Count(clip), h.Buf) h.freshClip = false - if clipboard.Unsupported { - InfoBar.Message("Pasted clipboard (install xclip for external clipboard)") - } else { - InfoBar.Message("Pasted clipboard") - } + InfoBar.Message("Pasted clipboard") } // JumpToMatchingBrace moves the cursor to the matching brace if it is @@ -1443,6 +1437,18 @@ func (h *BufPane) Escape() bool { return true } +// Deselect deselects on the current cursor +func (h *BufPane) Deselect() bool { + h.Cursor.Deselect(true) + return true +} + +// ClearInfo clears the infobar +func (h *BufPane) ClearInfo() bool { + InfoBar.Message("") + return true +} + // Quit this will close the current tab or view that is open func (h *BufPane) Quit() bool { quit := func() {