mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
do not highlight line if there are no items to display
This commit is contained in:
parent
00afa30ebf
commit
b838b74801
6 changed files with 16 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -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...)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue