diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-04-15 14:01:13 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-04-16 15:19:32 +1000 |
commit | b838b74801102b27782cc20c7396279630e77fba (patch) | |
tree | 7173208a9909fa1d33877fa9c019e556ea902eef /pkg | |
parent | 00afa30ebff2978e88cdab460b0f8ad818e1b502 (diff) |
do not highlight line if there are no items to display
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/context.go | 16 | ||||
-rw-r--r-- | pkg/gui/context/list_context_trait.go | 2 | ||||
-rw-r--r-- | pkg/gui/context/traits/list_cursor.go | 7 | ||||
-rw-r--r-- | pkg/gui/context/view_trait.go | 4 | ||||
-rw-r--r-- | pkg/gui/gui.go | 1 | ||||
-rw-r--r-- | pkg/gui/refresh.go | 10 |
6 files changed, 16 insertions, 24 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 8d3d91185..19db274d8 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -352,9 +352,6 @@ func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error { var previousView *gocui.View return func(g *gocui.Gui) error { newView := gui.g.CurrentView() - if err := gui.onViewFocusChange(); err != nil { - return err - } // for now we don't consider losing focus to a popup panel as actually losing focus if newView != previousView && !gui.isPopupPanel(newView.Name()) { if err := gui.onViewFocusLost(previousView, newView); err != nil { @@ -367,22 +364,13 @@ func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error { } } -func (gui *Gui) onViewFocusChange() error { - gui.g.Mutexes.ViewsMutex.Lock() - defer gui.g.Mutexes.ViewsMutex.Unlock() - - currentView := gui.g.CurrentView() - for _, view := range gui.g.Views() { - view.Highlight = view.Name() != "main" && view.Name() != "extras" && view == currentView - } - return nil -} - func (gui *Gui) onViewFocusLost(oldView *gocui.View, newView *gocui.View) error { if oldView == nil { return nil } + oldView.Highlight = false + _ = oldView.SetOriginX(0) return nil diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index a10f0e3e9..16587ec69 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -37,6 +37,8 @@ func formatListFooter(selectedLineIdx int, length int) string { func (self *ListContextTrait) HandleFocus(opts ...types.OnFocusOpts) error { self.FocusLine() + self.viewTrait.SetHighlight(self.list.Len() > 0) + return self.Context.HandleFocus(opts...) } diff --git a/pkg/gui/context/traits/list_cursor.go b/pkg/gui/context/traits/list_cursor.go index 6e80643d6..9e86d5139 100644 --- a/pkg/gui/context/traits/list_cursor.go +++ b/pkg/gui/context/traits/list_cursor.go @@ -25,7 +25,12 @@ func (self *ListCursor) GetSelectedLineIdx() int { } func (self *ListCursor) SetSelectedLineIdx(value int) { - self.selectedIdx = utils.Clamp(value, 0, self.list.Len()-1) + clampedValue := -1 + if self.list.Len() > 0 { + clampedValue = utils.Clamp(value, 0, self.list.Len()-1) + } + + self.selectedIdx = clampedValue } // moves the cursor up or down by the given amount diff --git a/pkg/gui/context/view_trait.go b/pkg/gui/context/view_trait.go index f7981ebfa..4c0cd9e05 100644 --- a/pkg/gui/context/view_trait.go +++ b/pkg/gui/context/view_trait.go @@ -31,6 +31,10 @@ func (self *ViewTrait) SetContent(content string) { self.view.SetContent(content) } +func (self *ViewTrait) SetHighlight(highlight bool) { + self.view.Highlight = highlight +} + func (self *ViewTrait) SetFooter(value string) { self.view.Footer = value } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 1af94088e..17ca26f41 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -654,7 +654,6 @@ func (gui *Gui) createAllViews() error { gui.Views.RemoteBranches.FgColor = theme.GocuiDefaultTextColor - gui.Views.Files.Highlight = true gui.Views.Files.Title = gui.c.Tr.FilesTitle gui.Views.Files.FgColor = theme.GocuiDefaultTextColor diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go index d3aaf9454..358555605 100644 --- a/pkg/gui/refresh.go +++ b/pkg/gui/refresh.go @@ -310,11 +310,8 @@ func (gui *Gui) refreshFilesAndSubmodules() error { gui.c.Log.Error(err) } - if gui.isContextVisible(gui.State.Contexts.Files) { - // doing this a little custom (as opposed to using gui.c.PostRefreshUpdate) because we handle selecting the file explicitly below - if err := gui.State.Contexts.Files.HandleRender(); err != nil { - return err - } + if err := gui.c.PostRefreshUpdate(gui.State.Contexts.Files); err != nil { + gui.c.Log.Error(err) } if gui.currentContext().GetKey() == context.FILES_CONTEXT_KEY { @@ -323,9 +320,6 @@ func (gui *Gui) refreshFilesAndSubmodules() error { if !alreadySelected { gui.takeOverMergeConflictScrolling() } - - gui.Views.Files.FocusPoint(0, gui.State.Contexts.Files.GetSelectedLineIdx()) - return gui.filesRenderToMain() } return nil |