From 0faa41e6f8e13818c611ad923fa424c83653d06a Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 26 Mar 2023 16:00:40 +1100 Subject: [PATCH] move toggle whitespace action to controllers package --- pkg/gui/controllers/global_controller.go | 9 ++++++++ .../controllers/toggle_whitespace_action.go | 21 +++++++++++++++++++ pkg/gui/keybindings.go | 6 ------ pkg/gui/whitespace-toggle.go | 17 --------------- 4 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 pkg/gui/controllers/toggle_whitespace_action.go delete mode 100644 pkg/gui/whitespace-toggle.go diff --git a/pkg/gui/controllers/global_controller.go b/pkg/gui/controllers/global_controller.go index 29843f00c..6f948a630 100644 --- a/pkg/gui/controllers/global_controller.go +++ b/pkg/gui/controllers/global_controller.go @@ -107,6 +107,11 @@ func (self *GlobalController) GetKeybindings(opts types.KeybindingsOpts) []*type Modifier: gocui.ModNone, Handler: self.escape, }, + { + Key: opts.GetKey(opts.Config.Universal.ToggleWhitespaceInDiffView), + Handler: self.toggleWhitespace, + Description: self.c.Tr.ToggleWhitespaceInDiffView, + }, } } @@ -157,3 +162,7 @@ func (self *GlobalController) quitWithoutChangingDirectory() error { func (self *GlobalController) escape() error { return (&QuitActions{c: self.c}).Escape() } + +func (self *GlobalController) toggleWhitespace() error { + return (&ToggleWhitespaceAction{c: self.c}).Call() +} diff --git a/pkg/gui/controllers/toggle_whitespace_action.go b/pkg/gui/controllers/toggle_whitespace_action.go new file mode 100644 index 000000000..56eb023f3 --- /dev/null +++ b/pkg/gui/controllers/toggle_whitespace_action.go @@ -0,0 +1,21 @@ +package controllers + +import ( + "github.com/jesseduffield/lazygit/pkg/gui/types" +) + +type ToggleWhitespaceAction struct { + c *ControllerCommon +} + +func (self *ToggleWhitespaceAction) Call() error { + self.c.State().SetIgnoreWhitespaceInDiffView(!self.c.State().GetIgnoreWhitespaceInDiffView()) + + toastMessage := self.c.Tr.ShowingWhitespaceInDiffView + if self.c.State().GetIgnoreWhitespaceInDiffView() { + toastMessage = self.c.Tr.IgnoringWhitespaceInDiffView + } + self.c.Toast(toastMessage) + + return self.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{}) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 11917045f..fa536b65d 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -258,12 +258,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi Handler: self.handleCopySelectedSideContextItemToClipboard, Description: self.c.Tr.LcCopySubmoduleNameToClipboard, }, - { - ViewName: "", - Key: opts.GetKey(opts.Config.Universal.ToggleWhitespaceInDiffView), - Handler: self.toggleWhitespaceInDiffView, - Description: self.c.Tr.ToggleWhitespaceInDiffView, - }, { ViewName: "extras", Key: gocui.MouseWheelUp, diff --git a/pkg/gui/whitespace-toggle.go b/pkg/gui/whitespace-toggle.go deleted file mode 100644 index dfbf541ff..000000000 --- a/pkg/gui/whitespace-toggle.go +++ /dev/null @@ -1,17 +0,0 @@ -package gui - -import ( - "github.com/jesseduffield/lazygit/pkg/gui/types" -) - -func (gui *Gui) toggleWhitespaceInDiffView() error { - gui.IgnoreWhitespaceInDiffView = !gui.IgnoreWhitespaceInDiffView - - toastMessage := gui.c.Tr.ShowingWhitespaceInDiffView - if gui.IgnoreWhitespaceInDiffView { - toastMessage = gui.c.Tr.IgnoringWhitespaceInDiffView - } - gui.c.Toast(toastMessage) - - return gui.c.CurrentSideContext().HandleFocus(types.OnFocusOpts{}) -}