Skip to content

statusline: Provide overwrite mode indicator #3620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var defaultCommonSettings = map[string]interface{}{
"softwrap": false,
"splitbottom": true,
"splitright": true,
"statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
"statusformatl": "$(filename) $(modified)$(overwrite)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
"statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help",
"statusline": true,
"syntax": true,
Expand Down
6 changes: 6 additions & 0 deletions internal/display/statusline.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
}
return ""
},
"overwrite": func(b *buffer.Buffer) string {
if b.OverwriteMode && !b.Type.Readonly {
return "[ovwr] "
}
return ""
},
"lines": func(b *buffer.Buffer) string {
return strconv.Itoa(b.LinesNum())
},
Expand Down
6 changes: 3 additions & 3 deletions runtime/help/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ Here are the available options:
* `statusformatl`: format string definition for the left-justified part of the
statusline. Special directives should be placed inside `$()`. Special
directives include: `filename`, `modified`, `line`, `col`, `lines`,
`percentage`, `opt`, `bind`.
`percentage`, `opt`, `overwrite`, `bind`.
The `opt` and `bind` directives take either an option or an action afterward
and fill in the value of the option or the key bound to the action.

default value: `$(filename) $(modified)($(line),$(col)) $(status.paste)|
default value: `$(filename) $(modified)$(overwrite)($(line),$(col)) $(status.paste)|
ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)`

* `statusformatr`: format string definition for the right-justified part of the
Expand Down Expand Up @@ -578,7 +578,7 @@ so that you can see what the formatting should look like.
"splitbottom": true,
"splitright": true,
"status": true,
"statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
"statusformatl": "$(filename) $(modified)$(overwrite)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
"statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help",
"statusline": true,
"sucmd": "sudo",
Expand Down