Fix: incorrect clipboard w/ CutLine, DeleteLine and Search (#508)

* Fix: incorrect clipboard w/ CutLine, DeleteLine and Search

* Refactor: Add Cursor.CopySelection(clipboard)
This commit is contained in:
Nicolai Søborg
2017-01-10 00:28:45 +01:00
committed by Zachary Yedidia
parent ae566920b6
commit 41fb57e449
3 changed files with 13 additions and 10 deletions

View File

@@ -29,6 +29,13 @@ func (c *Cursor) Goto(b Cursor) {
c.OrigSelection, c.CurSelection = b.OrigSelection, b.CurSelection
}
// CopySelection copies the user's selection to either "primary" or "clipboard"
func (c *Cursor) CopySelection(target string) {
if c.HasSelection() {
clipboard.WriteAll(c.GetSelection(), target)
}
}
// ResetSelection resets the user's selection
func (c *Cursor) ResetSelection() {
c.CurSelection[0] = c.buf.Start()
@@ -38,19 +45,11 @@ func (c *Cursor) ResetSelection() {
// SetSelectionStart sets the start of the selection
func (c *Cursor) SetSelectionStart(pos Loc) {
c.CurSelection[0] = pos
// Copy to primary clipboard for linux
if c.HasSelection() {
clipboard.WriteAll(c.GetSelection(), "primary")
}
}
// SetSelectionEnd sets the end of the selection
func (c *Cursor) SetSelectionEnd(pos Loc) {
c.CurSelection[1] = pos
// Copy to primary clipboard for linux
if c.HasSelection() {
clipboard.WriteAll(c.GetSelection(), "primary")
}
}
// HasSelection returns whether or not the user has selected anything