mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Toggling whitespace needs the panel beneath to render its diff again, which is what HandleRenderToMain is for; HandleFocus does that and also everything else that belongs to a panel gaining the focus, which this panel already has or, when the focus is in the main view, does not want. Re-selecting its current item is harmless, but re-deriving its highlight as a focused panel's is not: the selection turns bright while the user is somewhere else. Changing the context size and switching diff renderers already ask for a re-render this way. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
33 lines
953 B
Go
33 lines
953 B
Go
package controllers
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
type ToggleWhitespaceAction struct {
|
|
c *ControllerCommon
|
|
}
|
|
|
|
func (self *ToggleWhitespaceAction) Call() error {
|
|
contextsThatDontSupportIgnoringWhitespace := []types.ContextKey{
|
|
context.STAGING_MAIN_CONTEXT_KEY,
|
|
context.STAGING_SECONDARY_CONTEXT_KEY,
|
|
context.PATCH_BUILDING_MAIN_CONTEXT_KEY,
|
|
}
|
|
|
|
if lo.Contains(contextsThatDontSupportIgnoringWhitespace, self.c.Context().Current().GetKey()) {
|
|
// Ignoring whitespace is not supported in these views. Let the user
|
|
// know that it's not going to work in case they try to turn it on.
|
|
return errors.New(self.c.Tr.IgnoreWhitespaceNotSupportedHere)
|
|
}
|
|
|
|
self.c.UserConfig().Git.IgnoreWhitespaceInDiffView = !self.c.UserConfig().Git.IgnoreWhitespaceInDiffView
|
|
|
|
self.c.Context().CurrentSide().HandleRenderToMain()
|
|
return nil
|
|
}
|