MCPcopy
hub / github.com/micro-editor/micro / toggleOption

Method toggleOption

internal/action/command.go:747–782  ·  view source on GitHub ↗
(option string, local bool)

Source from the content-addressed store, hash-verified

745}
746
747func (h *BufPane) toggleOption(option string, local bool) error {
748 var curVal, newVal any
749
750 if local {
751 curVal = h.Buf.Settings[option]
752 } else {
753 curVal = config.GetGlobalOption(option)
754 }
755 if curVal == nil {
756 return config.ErrInvalidOption
757 }
758
759 if choices, ok := config.OptionChoices[option]; ok && len(choices) == 2 {
760 if curVal == choices[0] {
761 newVal = choices[1]
762 } else {
763 newVal = choices[0]
764 }
765 } else if curValBool, ok := curVal.(bool); ok {
766 newVal = !curValBool
767 } else {
768 return config.ErrOptNotToggleable
769 }
770
771 if local {
772 if err := h.Buf.SetOptionNative(option, newVal); err != nil {
773 return err
774 }
775 } else {
776 if err := SetGlobalOptionNative(option, newVal, true); err != nil {
777 return err
778 }
779 }
780
781 return nil
782}
783
784// ToggleCmd toggles a toggleable option
785func (h *BufPane) ToggleCmd(args []string) {

Callers 2

ToggleCmdMethod · 0.95
ToggleLocalCmdMethod · 0.95

Calls 3

GetGlobalOptionFunction · 0.92
SetGlobalOptionNativeFunction · 0.85
SetOptionNativeMethod · 0.80

Tested by

no test coverage detected