Skip to content

Commit 78fcf2f

Browse files
committed
Updated WordLeft() and WordRight() behavior to be in line with SubWordLeft() and SubWordRight()
1 parent 5dbdf8c commit 78fcf2f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

internal/buffer/cursor.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ func (c *Cursor) WordRight() {
410410
}
411411
c.Right()
412412
}
413+
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) &&
414+
util.IsNonWordChar(c.RuneUnder(c.X+1)) {
415+
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
416+
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
417+
c.Right()
418+
return
419+
}
420+
c.Right()
421+
}
422+
return
423+
}
413424
c.Right()
414425
for util.IsWordChar(c.RuneUnder(c.X)) {
415426
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
@@ -428,6 +439,17 @@ func (c *Cursor) WordLeft() {
428439
}
429440
c.Left()
430441
}
442+
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) &&
443+
util.IsNonWordChar(c.RuneUnder(c.X-1)) {
444+
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
445+
if c.X == 0 {
446+
return
447+
}
448+
c.Left()
449+
}
450+
c.Right()
451+
return
452+
}
431453
c.Left()
432454
for util.IsWordChar(c.RuneUnder(c.X)) {
433455
if c.X == 0 {

0 commit comments

Comments
 (0)