import (
"bytes"
- "hash/fnv"
)
// For storing multi cursor clipboard contents
buf := &bytes.Buffer{}
for _, s := range content {
buf.WriteString(s)
- buf.WriteByte('\n')
}
return buf.String()
}
return content[num]
}
-func hash(s string) uint32 {
- h := fnv.New32a()
- h.Write([]byte(s))
- return h.Sum32()
-}
-
// 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, ncursors int, clipboard string) bool {
+func (c multiClipboard) isValid(r Register, clipboard string, ncursors int) bool {
content := c[r]
if content == nil || len(content) != ncursors {
return false
}
- return hash(clipboard) == hash(c.getAllText(r))
+ return clipboard == c.getAllText(r)
}
-func (c multiClipboard) writeText(text string, r Register, num int) {
+func (c multiClipboard) writeText(text string, r Register, num int, ncursors int) {
content := c[r]
- if content == nil || num >= cap(content) {
- content = make([]string, num+1, num+1)
+ if content == nil || len(content) != ncursors {
+ content = make([]string, ncursors, ncursors)
+ c[r] = content
+ }
+
+ if num >= ncursors {
+ return
}
content[num] = text