(option string, local bool)
| 745 | } |
| 746 | |
| 747 | func (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 |
| 785 | func (h *BufPane) ToggleCmd(args []string) { |
no test coverage detected