Add delete key binding

Fixes #54
This commit is contained in:
Zachary Yedidia
2016-04-23 18:58:02 -04:00
parent 94c0f576e1
commit fa82fc2b74

View File

@@ -25,6 +25,7 @@ func InitBindings() {
"InsertEnter": InsertEnter,
"InsertSpace": InsertSpace,
"Backspace": Backspace,
"Delete": Delete,
"InsertTab": InsertTab,
"Save": Save,
"Find": Find,
@@ -231,6 +232,7 @@ func DefaultBindings() map[string]string {
"CtrlU": "HalfPageUp",
"CtrlD": "HalfPageDown",
"CtrlR": "ToggleRuler",
"Delete": "Delete",
}
}
@@ -333,6 +335,20 @@ func Backspace(v *View) bool {
return true
}
// Delete deletes the next character
func Delete(v *View) bool {
if v.cursor.HasSelection() {
v.cursor.DeleteSelection()
v.cursor.ResetSelection()
} else {
loc := v.cursor.Loc()
if loc < len(v.buf.text) {
v.eh.Remove(loc, loc+1)
}
}
return true
}
// InsertTab inserts a tab or spaces
func InsertTab(v *View) bool {
// Insert a tab