Skip to content

Commit 46e55c8

Browse files
authored
Fixed trailing line spaces being ignored by word- or subword-jumps (zyedidia#3321)
1 parent dd913df commit 46e55c8

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

internal/buffer/cursor.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,12 @@ func (c *Cursor) SelectTo(loc Loc) {
403403

404404
// WordRight moves the cursor one word to the right
405405
func (c *Cursor) WordRight() {
406+
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
407+
c.Right()
408+
return
409+
}
406410
for util.IsWhitespace(c.RuneUnder(c.X)) {
407411
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
408-
c.Right()
409412
return
410413
}
411414
c.Right()
@@ -414,7 +417,6 @@ func (c *Cursor) WordRight() {
414417
util.IsNonWordChar(c.RuneUnder(c.X+1)) {
415418
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
416419
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
417-
c.Right()
418420
return
419421
}
420422
c.Right()
@@ -432,6 +434,10 @@ func (c *Cursor) WordRight() {
432434

433435
// WordLeft moves the cursor one word to the left
434436
func (c *Cursor) WordLeft() {
437+
if c.X == 0 {
438+
c.Left()
439+
return
440+
}
435441
c.Left()
436442
for util.IsWhitespace(c.RuneUnder(c.X)) {
437443
if c.X == 0 {
@@ -462,10 +468,13 @@ func (c *Cursor) WordLeft() {
462468

463469
// SubWordRight moves the cursor one sub-word to the right
464470
func (c *Cursor) SubWordRight() {
471+
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
472+
c.Right()
473+
return
474+
}
465475
if util.IsWhitespace(c.RuneUnder(c.X)) {
466476
for util.IsWhitespace(c.RuneUnder(c.X)) {
467477
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
468-
c.Right()
469478
return
470479
}
471480
c.Right()
@@ -475,7 +484,6 @@ func (c *Cursor) SubWordRight() {
475484
if util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
476485
for util.IsNonWordChar(c.RuneUnder(c.X)) && !util.IsWhitespace(c.RuneUnder(c.X)) {
477486
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
478-
c.Right()
479487
return
480488
}
481489
c.Right()
@@ -485,7 +493,6 @@ func (c *Cursor) SubWordRight() {
485493
if util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
486494
for util.IsSubwordDelimiter(c.RuneUnder(c.X)) {
487495
if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
488-
c.Right()
489496
return
490497
}
491498
c.Right()
@@ -521,6 +528,10 @@ func (c *Cursor) SubWordRight() {
521528

522529
// SubWordLeft moves the cursor one sub-word to the left
523530
func (c *Cursor) SubWordLeft() {
531+
if c.X == 0 {
532+
c.Left()
533+
return
534+
}
524535
c.Left()
525536
if util.IsWhitespace(c.RuneUnder(c.X)) {
526537
for util.IsWhitespace(c.RuneUnder(c.X)) {

0 commit comments

Comments
 (0)