From ddc6051b33397f37460cbae3881c99e0932b79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 16 Feb 2025 18:01:18 +0100 Subject: [PATCH] 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 https://github.com/zyedidia/micro/pull/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. --- internal/action/actions.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 84a5060b..e06b7815 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1794,12 +1794,12 @@ func (h *BufPane) HalfPageDown() bool { // ToggleDiffGutter turns the diff gutter off and on func (h *BufPane) ToggleDiffGutter() bool { - if !h.Buf.Settings["diffgutter"].(bool) { - h.Buf.Settings["diffgutter"] = true + diffgutter := !h.Buf.Settings["diffgutter"].(bool) + h.Buf.SetOptionNative("diffgutter", diffgutter) + if diffgutter { h.Buf.UpdateDiff() InfoBar.Message("Enabled diff gutter") } else { - h.Buf.Settings["diffgutter"] = false InfoBar.Message("Disabled diff gutter") } return true @@ -1807,11 +1807,11 @@ func (h *BufPane) ToggleDiffGutter() bool { // ToggleRuler turns line numbers off and on func (h *BufPane) ToggleRuler() bool { - if !h.Buf.Settings["ruler"].(bool) { - h.Buf.Settings["ruler"] = true + ruler := !h.Buf.Settings["ruler"].(bool) + h.Buf.SetOptionNative("ruler", ruler) + if ruler { InfoBar.Message("Enabled ruler") } else { - h.Buf.Settings["ruler"] = false InfoBar.Message("Disabled ruler") } return true