From c61670e86fa30b0bf40b0bb0c2b912721bfa2284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:49:50 +0100 Subject: [PATCH] buffer: Store the overwrite mode --- internal/action/actions.go | 2 +- internal/action/bufpane.go | 7 +------ internal/buffer/buffer.go | 5 +++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index e67b7d1b..6058c574 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1864,7 +1864,7 @@ func (h *BufPane) CommandMode() bool { // ToggleOverwriteMode lets the user toggle the text overwrite mode func (h *BufPane) ToggleOverwriteMode() bool { - h.isOverwriteMode = !h.isOverwriteMode + h.Buf.OverwriteMode = !h.Buf.OverwriteMode return true } diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index da9c8868..0161fcc4 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -224,8 +224,6 @@ type BufPane struct { // (possibly multiple) buttons were pressed previously. mousePressed map[MouseEvent]bool - // We need to keep track of insert key press toggle - isOverwriteMode bool // This stores when the last click was // This is useful for detecting double and triple clicks lastClickTime time.Time @@ -358,9 +356,6 @@ func (h *BufPane) OpenBuffer(b *buffer.Buffer) { // Set mouseReleased to true because we assume the mouse is not being // pressed when the editor is opened h.resetMouse() - // Set isOverwriteMode to false, because we assume we are in the default - // mode when editor is opened - h.isOverwriteMode = false h.lastClickTime = time.Time{} } @@ -639,7 +634,7 @@ func (h *BufPane) DoRuneInsert(r rune) { c.ResetSelection() } - if h.isOverwriteMode { + if h.Buf.OverwriteMode { next := c.Loc next.X++ h.Buf.Replace(c.Loc, next, string(r)) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index c623fd58..1172dac8 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -209,6 +209,11 @@ type Buffer struct { LastSearchRegex bool // HighlightSearch enables highlighting all instances of the last successful search HighlightSearch bool + + // OverwriteMode indicates that we are in overwrite mode (toggled by + // Insert key by default) i.e. that typing a character shall replace the + // character under the cursor instead of inserting a character before it. + OverwriteMode bool } // NewBufferFromFileAtLoc opens a new buffer with a given cursor location