mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-23 15:30:21 +09:00
Improve WordRight and WordLeft bindings
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user