Updating to make overwrite mode as an action
This commit is contained in:
parent
b0e4043513
commit
f58c5412a8
3 changed files with 23 additions and 7 deletions
|
@ -1697,6 +1697,22 @@ func (v *View) CommandMode(usePlugin bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToggleOverwriteMode lets the user toggle the text overwrite mode
|
||||||
|
func (v *View) ToggleOverwriteMode(usePlugin bool) bool {
|
||||||
|
if v.mainCursor() {
|
||||||
|
if usePlugin && !PreActionCall("ToggleOverwriteMode", v) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
v.isOverwriteMode = !v.isOverwriteMode
|
||||||
|
|
||||||
|
if usePlugin {
|
||||||
|
return PostActionCall("ToggleOverwriteMode", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Escape leaves current mode
|
// Escape leaves current mode
|
||||||
func (v *View) Escape(usePlugin bool) bool {
|
func (v *View) Escape(usePlugin bool) bool {
|
||||||
if v.mainCursor() {
|
if v.mainCursor() {
|
||||||
|
|
|
@ -90,6 +90,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
||||||
"ClearStatus": (*View).ClearStatus,
|
"ClearStatus": (*View).ClearStatus,
|
||||||
"ShellMode": (*View).ShellMode,
|
"ShellMode": (*View).ShellMode,
|
||||||
"CommandMode": (*View).CommandMode,
|
"CommandMode": (*View).CommandMode,
|
||||||
|
"ToggleOverwriteMode": (*View).ToggleOverwriteMode,
|
||||||
"Escape": (*View).Escape,
|
"Escape": (*View).Escape,
|
||||||
"Quit": (*View).Quit,
|
"Quit": (*View).Quit,
|
||||||
"QuitAll": (*View).QuitAll,
|
"QuitAll": (*View).QuitAll,
|
||||||
|
@ -563,6 +564,7 @@ func DefaultBindings() map[string]string {
|
||||||
"CtrlW": "NextSplit",
|
"CtrlW": "NextSplit",
|
||||||
"CtrlU": "ToggleMacro",
|
"CtrlU": "ToggleMacro",
|
||||||
"CtrlJ": "PlayMacro",
|
"CtrlJ": "PlayMacro",
|
||||||
|
"Insert": "ToggleOverwriteMode",
|
||||||
|
|
||||||
// Emacs-style keybindings
|
// Emacs-style keybindings
|
||||||
"Alt-f": "WordRight",
|
"Alt-f": "WordRight",
|
||||||
|
|
|
@ -74,7 +74,7 @@ type View struct {
|
||||||
mouseReleased bool
|
mouseReleased bool
|
||||||
|
|
||||||
// We need to keep track of insert key press toggle
|
// We need to keep track of insert key press toggle
|
||||||
isInsertMode bool
|
isOverwriteMode bool
|
||||||
// This stores when the last click was
|
// This stores when the last click was
|
||||||
// This is useful for detecting double and triple clicks
|
// This is useful for detecting double and triple clicks
|
||||||
lastClickTime time.Time
|
lastClickTime time.Time
|
||||||
|
@ -247,9 +247,9 @@ func (v *View) OpenBuffer(buf *Buffer) {
|
||||||
// Set mouseReleased to true because we assume the mouse is not being pressed when
|
// Set mouseReleased to true because we assume the mouse is not being pressed when
|
||||||
// the editor is opened
|
// the editor is opened
|
||||||
v.mouseReleased = true
|
v.mouseReleased = true
|
||||||
// Set isInsertMode to false, because we assume we are in the default mode when editor
|
// Set isOverwriteMode to false, because we assume we are in the default mode when editor
|
||||||
// is opened
|
// is opened
|
||||||
v.isInsertMode = false
|
v.isOverwriteMode = false
|
||||||
v.lastClickTime = time.Time{}
|
v.lastClickTime = time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,9 +569,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e.Key() == tcell.KeyInsert {
|
|
||||||
v.isInsertMode = !v.isInsertMode
|
|
||||||
}
|
|
||||||
if !isBinding && e.Key() == tcell.KeyRune {
|
if !isBinding && e.Key() == tcell.KeyRune {
|
||||||
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
|
// Check viewtype if readonly don't insert a rune (readonly help and log view etc.)
|
||||||
if v.Type.Readonly == false {
|
if v.Type.Readonly == false {
|
||||||
|
@ -584,7 +582,7 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||||
v.Cursor.ResetSelection()
|
v.Cursor.ResetSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.isInsertMode {
|
if v.isOverwriteMode {
|
||||||
next := v.Cursor.Loc
|
next := v.Cursor.Loc
|
||||||
next.X++
|
next.X++
|
||||||
v.Buf.Replace(v.Cursor.Loc, next, string(e.Rune()))
|
v.Buf.Replace(v.Cursor.Loc, next, string(e.Rune()))
|
||||||
|
|
Loading…
Reference in a new issue