Skip to content

Commit

Permalink
buffer: Store the overwrite mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Jan 22, 2025
1 parent f5debdf commit c61670e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 1 addition & 6 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
}

Expand Down Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c61670e

Please sign in to comment.