Unselect for cursor movement actions

Fixes #250
This commit is contained in:
Zachary Yedidia
2016-08-31 08:51:24 -04:00
parent c661c65c8c
commit 59d2fa81dd

View File

@@ -44,6 +44,15 @@ func PostActionCall(funcName string, view *View) bool {
return relocate
}
func (v *View) deselect(index int) bool {
if v.Cursor.HasSelection() {
v.Cursor.Loc = v.Cursor.CurSelection[index]
v.Cursor.ResetSelection()
return true
}
return false
}
// Center centers the view on the cursor
func (v *View) Center(usePlugin bool) bool {
if usePlugin && !PreActionCall("Center", v) {
@@ -70,10 +79,7 @@ func (v *View) CursorUp(usePlugin bool) bool {
return false
}
if v.Cursor.HasSelection() {
v.Cursor.Loc = v.Cursor.CurSelection[0]
v.Cursor.ResetSelection()
}
v.deselect(0)
v.Cursor.Up()
if usePlugin {
@@ -88,10 +94,7 @@ func (v *View) CursorDown(usePlugin bool) bool {
return false
}
if v.Cursor.HasSelection() {
v.Cursor.Loc = v.Cursor.CurSelection[1]
v.Cursor.ResetSelection()
}
v.deselect(1)
v.Cursor.Down()
if usePlugin {
@@ -290,6 +293,8 @@ func (v *View) StartOfLine(usePlugin bool) bool {
return false
}
v.deselect(0)
v.Cursor.Start()
if usePlugin {
@@ -304,6 +309,8 @@ func (v *View) EndOfLine(usePlugin bool) bool {
return false
}
v.deselect(0)
v.Cursor.End()
if usePlugin {
@@ -369,6 +376,8 @@ func (v *View) CursorEnd(usePlugin bool) bool {
return false
}
v.deselect(0)
v.Cursor.Loc = v.Buf.End()
if usePlugin {
@@ -1089,6 +1098,8 @@ func (v *View) CursorPageUp(usePlugin bool) bool {
return false
}
v.deselect(0)
if v.Cursor.HasSelection() {
v.Cursor.Loc = v.Cursor.CurSelection[0]
v.Cursor.ResetSelection()
@@ -1107,6 +1118,8 @@ func (v *View) CursorPageDown(usePlugin bool) bool {
return false
}
v.deselect(0)
if v.Cursor.HasSelection() {
v.Cursor.Loc = v.Cursor.CurSelection[1]
v.Cursor.ResetSelection()