From 80755dcf31bb0f8db68f858b12977d23ec0d720c Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Wed, 27 Apr 2016 10:44:36 -0400 Subject: [PATCH] Improve word movement behavior --- cmd/micro/cursor.go | 8 ++++---- cmd/micro/util.go | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index feb47677..4bfe600a 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -218,10 +218,10 @@ func (c *Cursor) SelectTo(loc int) { // WordRight moves the cursor one word to the right func (c *Cursor) WordRight() { c.Right() - for !IsWordChar(string(c.RuneUnder(c.x))) { + for IsWhitespace(c.RuneUnder(c.x)) { c.Right() } - for IsWordChar(string(c.RuneUnder(c.x))) { + for !IsWhitespace(c.RuneUnder(c.x)) { c.Right() } } @@ -229,10 +229,10 @@ func (c *Cursor) WordRight() { // WordLeft moves the cursor one word to the left func (c *Cursor) WordLeft() { c.Left() - for !IsWordChar(string(c.RuneUnder(c.x))) { + for IsWhitespace(c.RuneUnder(c.x)) { c.Left() } - for IsWordChar(string(c.RuneUnder(c.x))) { + for !IsWhitespace(c.RuneUnder(c.x)) { c.Left() } c.Right() diff --git a/cmd/micro/util.go b/cmd/micro/util.go index b6a66326..f456705e 100644 --- a/cmd/micro/util.go +++ b/cmd/micro/util.go @@ -62,6 +62,11 @@ func IsWordChar(str string) bool { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_') } +// IsWhitespace returns true if the given rune is a space, tab, or newline +func IsWhitespace(c rune) bool { + return c == ' ' || c == '\t' || c == '\n' +} + // Contains returns whether or not a string array contains a given string func Contains(list []string, a string) bool { for _, b := range list {