Add clipboard support for multicursors

Fixes #1721
This commit is contained in:
Zachary Yedidia 2020-07-04 21:26:36 -04:00
parent d8596919a6
commit 037c3c993f
4 changed files with 17 additions and 6 deletions

View file

@ -995,7 +995,7 @@ func (h *BufPane) CutLine() bool {
if clip, err := clipboard.Read(clipboard.ClipboardReg); err != nil {
InfoBar.Error(err)
} else {
clipboard.Write(clip+string(h.Cursor.GetSelection()), clipboard.ClipboardReg)
clipboard.WriteMulti(clip+string(h.Cursor.GetSelection()), clipboard.ClipboardReg, h.Cursor.Num)
}
}
} else if time.Since(h.lastCutTime)/time.Second > 10*time.Second || h.freshClip == false {
@ -1139,7 +1139,7 @@ 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, err := clipboard.Read(clipboard.ClipboardReg)
clip, err := clipboard.ReadMulti(clipboard.ClipboardReg, h.Cursor.Num)
if err != nil {
InfoBar.Error(err)
} else {
@ -1151,7 +1151,7 @@ func (h *BufPane) Paste() bool {
// PastePrimary pastes from the primary clipboard (only use on linux)
func (h *BufPane) PastePrimary() bool {
clip, err := clipboard.Read(clipboard.PrimaryReg)
clip, err := clipboard.ReadMulti(clipboard.PrimaryReg, h.Cursor.Num)
if err != nil {
InfoBar.Error(err)
} else {

View file

@ -113,6 +113,7 @@ func BufMapKey(k Event, action string) {
cursors := h.Buf.GetCursors()
success := true
for i, a := range actionfns {
innerSuccess := true
for j, c := range cursors {
if c == nil {
continue
@ -120,13 +121,14 @@ func BufMapKey(k Event, action string) {
h.Buf.SetCurCursor(c.Num)
h.Cursor = c
if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') {
success = h.execAction(a, names[i], j)
innerSuccess = innerSuccess && h.execAction(a, names[i], j)
} else {
break
}
}
// if the action changed the current pane, update the reference
h = MainTab().CurPane()
success = innerSuccess
}
return true
}
@ -689,6 +691,7 @@ var MultiActions = map[string]bool{
"FindNext": true,
"FindPrevious": true,
"CopyLine": true,
"Copy": true,
"Cut": true,
"CutLine": true,
"DuplicateLine": true,

View file

@ -128,7 +128,7 @@ func (c *Cursor) End() {
func (c *Cursor) CopySelection(target clipboard.Register) {
if c.HasSelection() {
if target != clipboard.PrimaryReg || c.buf.Settings["useprimary"].(bool) {
clipboard.Write(string(c.GetSelection()), target)
clipboard.WriteMulti(string(c.GetSelection()), target, c.Num)
}
}
}

View file

@ -54,8 +54,16 @@ func (c multiClipboard) isValid(r Register, clipboard string) bool {
func (c multiClipboard) writeText(text string, r Register, num int) {
content := c[r]
if content == nil || num >= cap(content) {
if content == nil {
content = make([]string, num+1, num+1)
c[r] = content
}
if num >= cap(content) {
newctnt := make([]string, num+1, num+1)
copy(newctnt, content)
content = newctnt
c[r] = content
}
content[num] = text