mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-05 15:30:59 +00:00
Improve cursor word movement
The definition of a "word" is a bit more subtle now. Before it would just move the cursor until a whitespace was found. Now it will stop at non word characters as well.
This commit is contained in:
parent
9db4e640a0
commit
198b1b8e79
1 changed files with 6 additions and 5 deletions
|
|
@ -167,14 +167,15 @@ func (c *Cursor) SelectTo(loc Loc) {
|
|||
|
||||
// WordRight moves the cursor one word to the right
|
||||
func (c *Cursor) WordRight() {
|
||||
c.Right()
|
||||
for IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == Count(c.buf.Line(c.Y)) {
|
||||
c.Right()
|
||||
return
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
for !IsWhitespace(c.RuneUnder(c.X)) {
|
||||
c.Right()
|
||||
for IsWordChar(string(c.RuneUnder(c.X))) {
|
||||
if c.X == Count(c.buf.Line(c.Y)) {
|
||||
return
|
||||
}
|
||||
|
|
@ -184,20 +185,20 @@ func (c *Cursor) WordRight() {
|
|||
|
||||
// WordLeft moves the cursor one word to the left
|
||||
func (c *Cursor) WordLeft() {
|
||||
c.Left()
|
||||
for IsWhitespace(c.RuneUnder(c.X)) {
|
||||
if c.X == 0 {
|
||||
c.Left()
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
for !IsWhitespace(c.RuneUnder(c.X)) {
|
||||
c.Left()
|
||||
for IsWordChar(string(c.RuneUnder(c.X))) {
|
||||
if c.X == 0 {
|
||||
return
|
||||
}
|
||||
c.Left()
|
||||
}
|
||||
c.Right()
|
||||
}
|
||||
|
||||
// RuneUnder returns the rune under the given x position
|
||||
|
|
|
|||
Loading…
Reference in a new issue