Update WordRight command to move cursor to next word's first character

This commit is contained in:
Lincoln Júnior 2022-02-07 01:54:07 -03:00
parent f20179519f
commit 79517d1163
2 changed files with 34 additions and 5 deletions

View file

@ -308,7 +308,7 @@ func (h *BufPane) SelectWordRight() bool {
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
h.Cursor.WordRight()
h.Cursor.WordEnd()
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true

View file

@ -394,14 +394,15 @@ func (c *Cursor) SelectTo(loc Loc) {
}
}
// WordRight moves the cursor one word to the right
func (c *Cursor) WordRight() {
// WordEnd moves the cursor to the end of the next word or to the
// end of the word currently under it
func (c *Cursor) WordEnd() {
c.Right()
for util.IsWhitespace(c.RuneUnder(c.X)) {
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
c.Right()
return
}
c.Right()
c.Left()
}
c.Right()
for util.IsWordChar(c.RuneUnder(c.X)) {
@ -412,6 +413,34 @@ func (c *Cursor) WordRight() {
}
}
// skipRightWhiteSpaces moves the cursor until it reaches a non
// white space character
func (c *Cursor) skipRightWhiteSpaces() {
for util.IsWhitespace(c.RuneUnder(c.X)) {
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
c.Right()
return
}
c.Right()
}
}
// WordRight moves the cursor one word to the right
func (c *Cursor) WordRight() {
if !util.IsWordChar(c.RuneUnder(c.X)) {
c.Right()
c.skipRightWhiteSpaces()
} else {
for util.IsWordChar(c.RuneUnder(c.X)) {
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
return
}
c.Right()
}
c.skipRightWhiteSpaces()
}
}
// WordLeft moves the cursor one word to the left
func (c *Cursor) WordLeft() {
c.Left()