Fix some issues with mouse selection copying

This commit is contained in:
Zachary Yedidia
2016-09-05 08:36:30 -04:00
parent c71e816e37
commit 2041e12eba
2 changed files with 11 additions and 7 deletions

View File

@@ -31,22 +31,26 @@ func (c *Cursor) Goto(b Cursor) {
// ResetSelection resets the user's selection // ResetSelection resets the user's selection
func (c *Cursor) ResetSelection() { func (c *Cursor) ResetSelection() {
c.SetSelectionStart(c.buf.Start()) c.CurSelection[0] = c.buf.Start()
c.SetSelectionEnd(c.buf.Start()) c.CurSelection[1] = c.buf.Start()
} }
// SetSelectionStart sets the start of the selection // SetSelectionStart sets the start of the selection
func (c *Cursor) SetSelectionStart(pos Loc) { func (c *Cursor) SetSelectionStart(pos Loc) {
c.CurSelection[0] = pos c.CurSelection[0] = pos
// Copy to primary clipboard for linux // Copy to primary clipboard for linux
clipboard.WriteAll(c.GetSelection(), "primary") if c.HasSelection() {
clipboard.WriteAll(c.GetSelection(), "primary")
}
} }
// SetSelectionEnd sets the end of the selection // SetSelectionEnd sets the end of the selection
func (c *Cursor) SetSelectionEnd(pos Loc) { func (c *Cursor) SetSelectionEnd(pos Loc) {
c.CurSelection[1] = pos c.CurSelection[1] = pos
// Copy to primary clipboard for linux // Copy to primary clipboard for linux
clipboard.WriteAll(c.GetSelection(), "primary") if c.HasSelection() {
clipboard.WriteAll(c.GetSelection(), "primary")
}
} }
// HasSelection returns whether or not the user has selected anything // HasSelection returns whether or not the user has selected anything
@@ -59,7 +63,7 @@ func (c *Cursor) DeleteSelection() {
if c.CurSelection[0].GreaterThan(c.CurSelection[1]) { if c.CurSelection[0].GreaterThan(c.CurSelection[1]) {
c.buf.Remove(c.CurSelection[1], c.CurSelection[0]) c.buf.Remove(c.CurSelection[1], c.CurSelection[0])
c.Loc = c.CurSelection[1] c.Loc = c.CurSelection[1]
} else if c.GetSelection() == "" { } else if !c.HasSelection() {
return return
} else { } else {
c.buf.Remove(c.CurSelection[0], c.CurSelection[1]) c.buf.Remove(c.CurSelection[0], c.CurSelection[1])

View File

@@ -414,8 +414,8 @@ func (v *View) HandleEvent(event tcell.Event) {
v.lastClickTime = time.Now() v.lastClickTime = time.Now()
v.Cursor.OrigSelection[0] = v.Cursor.Loc v.Cursor.OrigSelection[0] = v.Cursor.Loc
v.Cursor.SetSelectionStart(v.Cursor.Loc) v.Cursor.CurSelection[0] = v.Cursor.Loc
v.Cursor.SetSelectionEnd(v.Cursor.Loc) v.Cursor.CurSelection[1] = v.Cursor.Loc
} }
v.mouseReleased = false v.mouseReleased = false
} else if !v.mouseReleased { } else if !v.mouseReleased {