From 3b2d7abe3d0610883bc630e7eeae7b754c3ef166 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 15 Jul 2017 17:52:56 -0400 Subject: [PATCH] Store visual x when cursor loc moves in certain cases Fixes #739 --- cmd/micro/actions.go | 6 ++++++ cmd/micro/cursor.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 04b8304b..a4e6cd0b 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -47,6 +47,7 @@ func (v *View) deselect(index int) bool { if v.Cursor.HasSelection() { v.Cursor.Loc = v.Cursor.CurSelection[index] v.Cursor.ResetSelection() + v.Cursor.StoreVisualX() return true } return false @@ -215,6 +216,7 @@ func (v *View) CursorLeft(usePlugin bool) bool { if v.Cursor.HasSelection() { v.Cursor.Loc = v.Cursor.CurSelection[0] v.Cursor.ResetSelection() + v.Cursor.StoreVisualX() } else { tabstospaces := v.Buf.Settings["tabstospaces"].(bool) tabmovement := v.Buf.Settings["tabmovement"].(bool) @@ -248,6 +250,7 @@ func (v *View) CursorRight(usePlugin bool) bool { if v.Cursor.HasSelection() { v.Cursor.Loc = v.Cursor.CurSelection[1].Move(-1, v.Buf) v.Cursor.ResetSelection() + v.Cursor.StoreVisualX() } else { tabstospaces := v.Buf.Settings["tabstospaces"].(bool) tabmovement := v.Buf.Settings["tabmovement"].(bool) @@ -512,6 +515,7 @@ func (v *View) CursorEnd(usePlugin bool) bool { v.deselect(0) v.Cursor.Loc = v.Buf.End() + v.Cursor.StoreVisualX() if usePlugin { return PostActionCall("CursorEnd", v) @@ -1373,6 +1377,7 @@ func (v *View) CursorPageUp(usePlugin bool) bool { if v.Cursor.HasSelection() { v.Cursor.Loc = v.Cursor.CurSelection[0] v.Cursor.ResetSelection() + v.Cursor.StoreVisualX() } v.Cursor.UpN(v.Height) @@ -1393,6 +1398,7 @@ func (v *View) CursorPageDown(usePlugin bool) bool { if v.Cursor.HasSelection() { v.Cursor.Loc = v.Cursor.CurSelection[1] v.Cursor.ResetSelection() + v.Cursor.StoreVisualX() } v.Cursor.DownN(v.Height) diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 67391338..a0d3477f 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -350,6 +350,11 @@ func (c *Cursor) GetVisualX() int { return StringWidth(string(runes[:c.X]), tabSize) } +// StoreVisualX stores the current visual x value in the cursor +func (c *Cursor) StoreVisualX() { + c.LastVisualX = c.GetVisualX() +} + // Relocate makes sure that the cursor is inside the bounds of the buffer // If it isn't, it moves it to be within the buffer's lines func (c *Cursor) Relocate() {