Store visual x when cursor loc moves in certain cases

Fixes #739
This commit is contained in:
Zachary Yedidia
2017-07-15 17:52:56 -04:00
parent 18ad74a982
commit 3b2d7abe3d
2 changed files with 11 additions and 0 deletions

View File

@@ -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)

View File

@@ -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() {