From 6c99eea6105ebc550d3e2a7cf3a48dcae9aa4060 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Tue, 26 Apr 2016 09:53:46 -0400 Subject: [PATCH] Improve WordRight and WordLeft bindings --- cmd/micro/bindings.go | 18 +++++++++++++----- cmd/micro/cursor.go | 11 +++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index 4bc282ba..8e201187 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -289,8 +289,12 @@ func (v *View) CursorDown() bool { // CursorLeft moves the cursor left func (v *View) CursorLeft() bool { - v.cursor.ResetSelection() - v.cursor.Left() + if v.cursor.HasSelection() { + v.cursor.SetLoc(v.cursor.curSelection[0]) + v.cursor.ResetSelection() + } else { + v.cursor.Left() + } return true } @@ -330,7 +334,7 @@ func (v *View) SelectWordRight() bool { v.cursor.origSelection[0] = loc } v.cursor.WordRight() - v.cursor.SelectTo(v.cursor.Loc()) + v.cursor.SelectTo(v.cursor.Loc() - 1) return true } @@ -346,8 +350,12 @@ func (v *View) SelectWordLeft() bool { // CursorRight moves the cursor right func (v *View) CursorRight() bool { - v.cursor.ResetSelection() - v.cursor.Right() + if v.cursor.HasSelection() { + v.cursor.SetLoc(v.cursor.curSelection[1] - 1) + v.cursor.ResetSelection() + } else { + v.cursor.Right() + } return true } diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 4d2bd1f6..bea87e3e 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -215,17 +215,24 @@ func (c *Cursor) SelectTo(loc int) { } func (c *Cursor) WordRight() { + c.Right() + for !IsWordChar(string(c.RuneUnder(c.x))) { + c.Right() + } for IsWordChar(string(c.RuneUnder(c.x))) { c.Right() } - c.Right() } func (c *Cursor) WordLeft() { + c.Left() + for !IsWordChar(string(c.RuneUnder(c.x))) { + c.Left() + } for IsWordChar(string(c.RuneUnder(c.x))) { c.Left() } - c.Left() + c.Right() } // RuneUnder returns the rune under the given x position