Improve WordRight and WordLeft bindings

This commit is contained in:
Zachary Yedidia
2016-04-26 09:53:46 -04:00
parent e00e0cfa3f
commit 6c99eea610
2 changed files with 22 additions and 7 deletions

View File

@@ -289,8 +289,12 @@ func (v *View) CursorDown() bool {
// CursorLeft moves the cursor left
func (v *View) CursorLeft() bool {
v.cursor.ResetSelection()
v.cursor.Left()
if v.cursor.HasSelection() {
v.cursor.SetLoc(v.cursor.curSelection[0])
v.cursor.ResetSelection()
} else {
v.cursor.Left()
}
return true
}
@@ -330,7 +334,7 @@ func (v *View) SelectWordRight() bool {
v.cursor.origSelection[0] = loc
}
v.cursor.WordRight()
v.cursor.SelectTo(v.cursor.Loc())
v.cursor.SelectTo(v.cursor.Loc() - 1)
return true
}
@@ -346,8 +350,12 @@ func (v *View) SelectWordLeft() bool {
// CursorRight moves the cursor right
func (v *View) CursorRight() bool {
v.cursor.ResetSelection()
v.cursor.Right()
if v.cursor.HasSelection() {
v.cursor.SetLoc(v.cursor.curSelection[1] - 1)
v.cursor.ResetSelection()
} else {
v.cursor.Right()
}
return true
}

View File

@@ -215,17 +215,24 @@ func (c *Cursor) SelectTo(loc int) {
}
func (c *Cursor) WordRight() {
c.Right()
for !IsWordChar(string(c.RuneUnder(c.x))) {
c.Right()
}
for IsWordChar(string(c.RuneUnder(c.x))) {
c.Right()
}
c.Right()
}
func (c *Cursor) WordLeft() {
c.Left()
for !IsWordChar(string(c.RuneUnder(c.x))) {
c.Left()
}
for IsWordChar(string(c.RuneUnder(c.x))) {
c.Left()
}
c.Left()
c.Right()
}
// RuneUnder returns the rune under the given x position