From 198b1b8e795d9d0d3206ff07bdbaeb0ab5047709 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 20 Aug 2016 12:26:54 -0700 Subject: [PATCH] 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. --- cmd/micro/cursor.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 03ddf159..c902ae0b 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -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