diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-03-26 16:00:40 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:53 +1000 |
commit | 0faa41e6f8e13818c611ad923fa424c83653d06a (patch) | |
tree | dcbe6098484cc253fa026f02b18ec89ce68e8335 /pkg/gui | |
parent | 2e32e55957d72153a7219d3898e6c95e7880699b (diff) |
move toggle whitespace action to controllers package
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/controllers/global_controller.go | 9 | ||||
-rw-r--r-- | pkg/gui/controllers/toggle_whitespace_action.go | 21 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 6 | ||||
-rw-r--r-- | pkg/gui/whitespace-toggle.go | 17 |
4 files changed, 30 insertions, 23 deletions
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 @@ -259,12 +259,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi 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, Handler: self.scrollUpExtra, 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{}) -} |