Skip to content

Commit e4b0ad7

Browse files
authored
Merge pull request zyedidia#3620 from JoeKar/feature/cursor-overwrite-indicator
statusline: Provide `overwrite` mode indicator
2 parents 5ee7fb6 + 57a6e81 commit e4b0ad7

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

internal/action/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,7 @@ func (h *BufPane) CommandMode() bool {
18641864

18651865
// ToggleOverwriteMode lets the user toggle the text overwrite mode
18661866
func (h *BufPane) ToggleOverwriteMode() bool {
1867-
h.isOverwriteMode = !h.isOverwriteMode
1867+
h.Buf.OverwriteMode = !h.Buf.OverwriteMode
18681868
return true
18691869
}
18701870

internal/action/bufpane.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ type BufPane struct {
224224
// (possibly multiple) buttons were pressed previously.
225225
mousePressed map[MouseEvent]bool
226226

227-
// We need to keep track of insert key press toggle
228-
isOverwriteMode bool
229227
// This stores when the last click was
230228
// This is useful for detecting double and triple clicks
231229
lastClickTime time.Time
@@ -358,9 +356,6 @@ func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
358356
// Set mouseReleased to true because we assume the mouse is not being
359357
// pressed when the editor is opened
360358
h.resetMouse()
361-
// Set isOverwriteMode to false, because we assume we are in the default
362-
// mode when editor is opened
363-
h.isOverwriteMode = false
364359
h.lastClickTime = time.Time{}
365360
}
366361

@@ -639,7 +634,7 @@ func (h *BufPane) DoRuneInsert(r rune) {
639634
c.ResetSelection()
640635
}
641636

642-
if h.isOverwriteMode {
637+
if h.Buf.OverwriteMode {
643638
next := c.Loc
644639
next.X++
645640
h.Buf.Replace(c.Loc, next, string(r))

internal/buffer/buffer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ type Buffer struct {
209209
LastSearchRegex bool
210210
// HighlightSearch enables highlighting all instances of the last successful search
211211
HighlightSearch bool
212+
213+
// OverwriteMode indicates that we are in overwrite mode (toggled by
214+
// Insert key by default) i.e. that typing a character shall replace the
215+
// character under the cursor instead of inserting a character before it.
216+
OverwriteMode bool
212217
}
213218

214219
// NewBufferFromFileAtLoc opens a new buffer with a given cursor location

internal/config/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ var defaultCommonSettings = map[string]interface{}{
9393
"softwrap": false,
9494
"splitbottom": true,
9595
"splitright": true,
96-
"statusformatl": "$(filename) $(modified)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
96+
"statusformatl": "$(filename) $(modified)$(overwrite)($(line),$(col)) $(status.paste)| ft:$(opt:filetype) | $(opt:fileformat) | $(opt:encoding)",
9797
"statusformatr": "$(bind:ToggleKeyMenu): bindings, $(bind:ToggleHelp): help",
9898
"statusline": true,
9999
"syntax": true,

internal/display/statusline.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ var statusInfo = map[string]func(*buffer.Buffer) string{
4747
}
4848
return ""
4949
},
50+
"overwrite": func(b *buffer.Buffer) string {
51+
if b.OverwriteMode && !b.Type.Readonly {
52+
return "[ovwr] "
53+
}
54+
return ""
55+
},
5056
"lines": func(b *buffer.Buffer) string {
5157
return strconv.Itoa(b.LinesNum())
5258
},

runtime/help/options.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ Here are the available options:
409409
* `statusformatl`: format string definition for the left-justified part of the
410410
statusline. Special directives should be placed inside `$()`. Special
411411
directives include: `filename`, `modified`, `line`, `col`, `lines`,
412-
`percentage`, `opt`, `bind`.
412+
`percentage`, `opt`, `overwrite`, `bind`.
413413
The `opt` and `bind` directives take either an option or an action afterward
414414
and fill in the value of the option or the key bound to the action.
415415

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

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

0 commit comments

Comments
 (0)