Something went wrong. Try again.
Fork of micro-editor/micro
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364package clipboard
import ( "bytes")
// For storing multi cursor clipboard contentstype multiClipboard map[Register][]string
var multi multiClipboard
func (c multiClipboard) getAllText(r Register) string { content := c[r] if content == nil { return "" }
buf := &bytes.Buffer{} for _, s := range content { buf.WriteString(s) } return buf.String()}
func (c multiClipboard) getText(r Register, num int) string { content := c[r] if content == nil || len(content) <= num { return "" }
return content[num]}
// isValid checks if the text stored in this multi-clipboard is the same as the// text stored in the system clipboard (provided as an argument), and therefore// if it is safe to use the multi-clipboard for pasting instead of the system// clipboard.func (c multiClipboard) isValid(r Register, clipboard string, ncursors int) bool { content := c[r] if content == nil || len(content) != ncursors { return false }
return clipboard == c.getAllText(r)}
func (c multiClipboard) writeText(text string, r Register, num int, ncursors int) { content := c[r] if content == nil || len(content) != ncursors { content = make([]string, ncursors, ncursors) c[r] = content }
if num >= ncursors { return }
content[num] = text}
func init() { multi = make(multiClipboard)}