Skip to content

Commit ddc6051

Browse files
committed
actions: Use SetOptionNative() instead of setting options directly
Setting options directly in (h.)Buf.Settings without calling SetOption() or SetOptionNative() is generally not the best idea, since it may not trigger the needed side effects. In particular, after micro-editor#3343, directly setting `diffgutter` and `ruler` causes them not being tracked as locally overridden per buffer, so if we run the `reload` command, it unexpectedly replaces them with the default ones.
1 parent 2e94235 commit ddc6051

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

internal/action/actions.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,24 +1794,24 @@ func (h *BufPane) HalfPageDown() bool {
17941794

17951795
// ToggleDiffGutter turns the diff gutter off and on
17961796
func (h *BufPane) ToggleDiffGutter() bool {
1797-
if !h.Buf.Settings["diffgutter"].(bool) {
1798-
h.Buf.Settings["diffgutter"] = true
1797+
diffgutter := !h.Buf.Settings["diffgutter"].(bool)
1798+
h.Buf.SetOptionNative("diffgutter", diffgutter)
1799+
if diffgutter {
17991800
h.Buf.UpdateDiff()
18001801
InfoBar.Message("Enabled diff gutter")
18011802
} else {
1802-
h.Buf.Settings["diffgutter"] = false
18031803
InfoBar.Message("Disabled diff gutter")
18041804
}
18051805
return true
18061806
}
18071807

18081808
// ToggleRuler turns line numbers off and on
18091809
func (h *BufPane) ToggleRuler() bool {
1810-
if !h.Buf.Settings["ruler"].(bool) {
1811-
h.Buf.Settings["ruler"] = true
1810+
ruler := !h.Buf.Settings["ruler"].(bool)
1811+
h.Buf.SetOptionNative("ruler", ruler)
1812+
if ruler {
18121813
InfoBar.Message("Enabled ruler")
18131814
} else {
1814-
h.Buf.Settings["ruler"] = false
18151815
InfoBar.Message("Disabled ruler")
18161816
}
18171817
return true

0 commit comments

Comments
 (0)