Skip to content

Commit

Permalink
Fix: incorrect clipboard w/ CutLine, DeleteLine and Search (zyedidia#508
Browse files Browse the repository at this point in the history
)

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

* Refactor: Add Cursor.CopySelection(clipboard)
  • Loading branch information
NicolaiSoeborg authored and zyedidia committed Jan 9, 2017
1 parent ae56692 commit 41fb57e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/micro/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ func (v *View) Copy(usePlugin bool) bool {
}

if v.Cursor.HasSelection() {
clipboard.WriteAll(v.Cursor.GetSelection(), "clipboard")
v.Cursor.CopySelection("clipboard")
v.freshClip = true
messenger.Message("Copied selection")
}
Expand Down Expand Up @@ -903,7 +903,7 @@ func (v *View) Cut(usePlugin bool) bool {
}

if v.Cursor.HasSelection() {
clipboard.WriteAll(v.Cursor.GetSelection(), "clipboard")
v.Cursor.CopySelection("clipboard")
v.Cursor.DeleteSelection()
v.Cursor.ResetSelection()
v.freshClip = true
Expand Down
15 changes: 7 additions & 8 deletions cmd/micro/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmd/micro/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func (v *View) HandleEvent(event tcell.Event) {
v.doubleClick = false

v.Cursor.SelectLine()
v.Cursor.CopySelection("primary")
} else {
// Double click
v.lastClickTime = time.Now()
Expand All @@ -540,6 +541,7 @@ func (v *View) HandleEvent(event tcell.Event) {
v.tripleClick = false

v.Cursor.SelectWord()
v.Cursor.CopySelection("primary")
}
} else {
v.doubleClick = false
Expand All @@ -559,6 +561,7 @@ func (v *View) HandleEvent(event tcell.Event) {
v.Cursor.AddWordToSelection()
} else {
v.Cursor.SetSelectionEnd(v.Cursor.Loc)
v.Cursor.CopySelection("primary")
}
}
case tcell.Button2:
Expand All @@ -579,6 +582,7 @@ func (v *View) HandleEvent(event tcell.Event) {
if !v.doubleClick && !v.tripleClick {
v.MoveToMouseClick(x, y)
v.Cursor.SetSelectionEnd(v.Cursor.Loc)
v.Cursor.CopySelection("primary")
}
v.mouseReleased = true
}
Expand Down

0 comments on commit 41fb57e

Please sign in to comment.