Changes to add support for Insert Key Press

This commit is contained in:
Nitish Sakhawalkar
2017-12-15 14:43:37 -08:00
parent fa84f6ddc3
commit b0e4043513

View File

@@ -73,6 +73,8 @@ type View struct {
// mouse release events
mouseReleased bool
// We need to keep track of insert key press toggle
isInsertMode bool
// This stores when the last click was
// This is useful for detecting double and triple clicks
lastClickTime time.Time
@@ -245,6 +247,9 @@ func (v *View) OpenBuffer(buf *Buffer) {
// Set mouseReleased to true because we assume the mouse is not being pressed when
// the editor is opened
v.mouseReleased = true
// Set isInsertMode to false, because we assume we are in the default mode when editor
// is opened
v.isInsertMode = false
v.lastClickTime = time.Time{}
}
@@ -564,6 +569,9 @@ func (v *View) HandleEvent(event tcell.Event) {
}
}
}
if e.Key() == tcell.KeyInsert {
v.isInsertMode = !v.isInsertMode
}
if !isBinding && e.Key() == tcell.KeyRune {
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
if v.Type.Readonly == false {
@@ -575,7 +583,14 @@ func (v *View) HandleEvent(event tcell.Event) {
v.Cursor.DeleteSelection()
v.Cursor.ResetSelection()
}
v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
if v.isInsertMode {
next := v.Cursor.Loc
next.X++
v.Buf.Replace(v.Cursor.Loc, next, string(e.Rune()))
} else {
v.Buf.Insert(v.Cursor.Loc, string(e.Rune()))
}
for pl := range loadedPlugins {
_, err := Call(pl+".onRune", string(e.Rune()), v)