1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

update view cursor when selecting new line in patch explorer view

This commit is contained in:
Jesse Duffield
2023-02-16 21:31:10 +11:00
parent 8cad8cda8f
commit c517d1e0a2
8 changed files with 82 additions and 45 deletions

View File

@ -5,7 +5,6 @@ import (
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
)
@ -89,9 +88,6 @@ func (self *ViewDriver) Content(matcher *matcher) *ViewDriver {
func (self *ViewDriver) SelectedLine(matcher *matcher) *ViewDriver {
self.t.matchString(matcher, fmt.Sprintf("%s: Unexpected selected line.", self.context),
func() string {
if idx, ok := self.selectedLineIdxInPatchExplorer(); ok {
return self.getView().BufferLines()[idx]
}
return self.getView().SelectedLine()
},
)
@ -102,25 +98,13 @@ func (self *ViewDriver) SelectedLine(matcher *matcher) *ViewDriver {
// asserts on the index of the selected line. 0 is the first index, representing the line at the top of the view.
func (self *ViewDriver) SelectedLineIdx(expected int) *ViewDriver {
self.t.assertWithRetries(func() (bool, string) {
actual, ok := self.selectedLineIdxInPatchExplorer()
if !ok {
actual = self.getView().SelectedLineIdx()
}
actual := self.getView().SelectedLineIdx()
return expected == actual, fmt.Sprintf("%s: Expected selected line index to be %d, got %d", self.context, expected, actual)
})
return self
}
func (self *ViewDriver) selectedLineIdxInPatchExplorer() (int, bool) {
context := self.t.gui.ContextForView(self.getView().Name())
patchExplorerContext, ok := context.(types.IPatchExplorerContext)
if ok && patchExplorerContext.GetState() != nil {
return patchExplorerContext.GetState().GetSelectedLineIdx(), true
}
return 0, false
}
// focus the view (assumes the view is a side-view)
func (self *ViewDriver) Focus() *ViewDriver {
viewName := self.getView().Name()