summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-06-23 14:46:36 +0200
committerGitHub <noreply@github.com>2024-06-23 14:46:36 +0200
commit2ccd9980e3424ca80dfb6564883b0abb38564bfd (patch)
tree9ace69f07c9770c698fce4eeccde3385a7c03348 /pkg/gui
parentcf40a5b077343cf6cf3de50b60fc4b47ce929dc1 (diff)
parentdb0a1586d99393cda79e6022f3b3b8b4138b0e8b (diff)
Fix wrong highlight in staging panel when entering file with only staged changes (#3667)
Reproduction recipe: 1. stage all changes in a file by pressing space on it in the files panel 2. enter the staged changes panel by pressing enter 3. unstage one of the changes This makes the unstaged changes panel visible, but keeps the focus in the staged changes panel. However, the highlight in the unstaged changes view becomes visible, as if it were focused. Fixes #3664
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/context.go4
-rw-r--r--pkg/gui/context/simple_context.go2
-rw-r--r--pkg/gui/context/view_trait.go1
-rw-r--r--pkg/gui/gui.go2
-rw-r--r--pkg/gui/layout.go29
-rw-r--r--pkg/gui/views.go1
6 files changed, 9 insertions, 30 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index be5a720e3..28ecf2405 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -230,6 +230,10 @@ func (self *ContextMgr) ActivateContext(c types.Context, opts types.OnFocusOpts)
self.gui.helpers.Window.SetWindowContext(c)
self.gui.helpers.Window.MoveToTopOfWindow(c)
+ oldView := self.gui.c.GocuiGui().CurrentView()
+ if oldView != nil && oldView.Name() != viewName {
+ oldView.HighlightInactive = true
+ }
if _, err := self.gui.c.GocuiGui().SetCurrentView(viewName); err != nil {
return err
}
diff --git a/pkg/gui/context/simple_context.go b/pkg/gui/context/simple_context.go
index 7c00e09f7..cef871cef 100644
--- a/pkg/gui/context/simple_context.go
+++ b/pkg/gui/context/simple_context.go
@@ -52,6 +52,8 @@ func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) error {
}
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) error {
+ self.GetViewTrait().SetHighlight(false)
+ _ = self.view.SetOriginX(0)
if self.onFocusLostFn != nil {
return self.onFocusLostFn(opts)
}
diff --git a/pkg/gui/context/view_trait.go b/pkg/gui/context/view_trait.go
index 191419897..5342071ef 100644
--- a/pkg/gui/context/view_trait.go
+++ b/pkg/gui/context/view_trait.go
@@ -49,6 +49,7 @@ func (self *ViewTrait) SetContent(content string) {
func (self *ViewTrait) SetHighlight(highlight bool) {
self.view.Highlight = highlight
+ self.view.HighlightInactive = false
}
func (self *ViewTrait) SetFooter(value string) {
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 06228e759..66fe5cb9c 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -678,7 +678,7 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
return err
}
- gui.g.SetManager(gocui.ManagerFunc(gui.layout), gocui.ManagerFunc(gui.getFocusLayout()))
+ gui.g.SetManager(gocui.ManagerFunc(gui.layout))
if err := gui.createAllViews(); err != nil {
return err
diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go
index 2123731e4..861bb0bd1 100644
--- a/pkg/gui/layout.go
+++ b/pkg/gui/layout.go
@@ -288,35 +288,6 @@ func (gui *Gui) onInitialViewsCreation() error {
return nil
}
-// getFocusLayout returns a manager function for when view gain and lose focus
-func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error {
- var previousView *gocui.View
- return func(g *gocui.Gui) error {
- newView := gui.g.CurrentView()
- // for now we don't consider losing focus to a popup panel as actually losing focus
- if newView != previousView && !gui.helpers.Confirmation.IsPopupPanel(newView.Name()) {
- if err := gui.onViewFocusLost(previousView); err != nil {
- return err
- }
-
- previousView = newView
- }
- return nil
- }
-}
-
-func (gui *Gui) onViewFocusLost(oldView *gocui.View) error {
- if oldView == nil {
- return nil
- }
-
- oldView.Highlight = false
-
- _ = oldView.SetOriginX(0)
-
- return nil
-}
-
func (gui *Gui) transientContexts() []types.Context {
return lo.Filter(gui.State.Contexts.Flatten(), func(context types.Context, _ int) bool {
return context.IsTransient()
diff --git a/pkg/gui/views.go b/pkg/gui/views.go
index 9fd775764..9a4fa0a47 100644
--- a/pkg/gui/views.go
+++ b/pkg/gui/views.go
@@ -92,6 +92,7 @@ func (gui *Gui) createAllViews() error {
(*mapping.viewPtr).FrameRunes = frameRunes
(*mapping.viewPtr).FgColor = theme.GocuiDefaultTextColor
(*mapping.viewPtr).SelBgColor = theme.GocuiSelectedLineBgColor
+ (*mapping.viewPtr).InactiveViewSelBgColor = theme.GocuiInactiveViewSelectedLineBgColor
}
gui.Views.Options.Frame = false