mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-08 22:52:12 +02:00
Only render visible portion of the screen for commits view
This commit is contained in:
@@ -431,6 +431,11 @@ func (self *ViewDriver) SelectPreviousItem() *ViewDriver {
|
||||
return self.PressFast(self.t.keys.Universal.PrevItem)
|
||||
}
|
||||
|
||||
// i.e. pressing '<'
|
||||
func (self *ViewDriver) GotoTop() *ViewDriver {
|
||||
return self.PressFast(self.t.keys.Universal.GotoTop)
|
||||
}
|
||||
|
||||
// i.e. pressing space
|
||||
func (self *ViewDriver) PressPrimaryAction() *ViewDriver {
|
||||
return self.Press(self.t.keys.Universal.Select)
|
||||
@@ -457,21 +462,15 @@ func (self *ViewDriver) PressEscape() *ViewDriver {
|
||||
// - the user is not in a list item
|
||||
// - no list item is found containing the given text
|
||||
// - multiple list items are found containing the given text in the initial page of items
|
||||
//
|
||||
// NOTE: this currently assumes that BufferLines returns all the lines that can be accessed.
|
||||
// If this changes in future, we'll need to update this code to first attempt to find the item
|
||||
// in the current page and failing that, jump to the top of the view and iterate through all of it,
|
||||
// looking for the item.
|
||||
func (self *ViewDriver) NavigateToLine(matcher *TextMatcher) *ViewDriver {
|
||||
self.IsFocused()
|
||||
|
||||
view := self.getView()
|
||||
lines := view.BufferLines()
|
||||
|
||||
var matchIndex int
|
||||
matchIndex := -1
|
||||
|
||||
self.t.assertWithRetries(func() (bool, string) {
|
||||
matchIndex = -1
|
||||
var matches []string
|
||||
// first we look for a duplicate on the current screen. We won't bother looking beyond that though.
|
||||
for i, line := range lines {
|
||||
@@ -483,13 +482,19 @@ func (self *ViewDriver) NavigateToLine(matcher *TextMatcher) *ViewDriver {
|
||||
}
|
||||
if len(matches) > 1 {
|
||||
return false, fmt.Sprintf("Found %d matches for `%s`, expected only a single match. Matching lines:\n%s", len(matches), matcher.name(), strings.Join(matches, "\n"))
|
||||
} else if len(matches) == 0 {
|
||||
return false, fmt.Sprintf("Could not find item matching: %s. Lines:\n%s", matcher.name(), strings.Join(lines, "\n"))
|
||||
} else {
|
||||
return true, ""
|
||||
}
|
||||
return true, ""
|
||||
})
|
||||
|
||||
// If no match was found, it could be that this is a view that renders only
|
||||
// the visible lines. In that case, we jump to the top and then press
|
||||
// down-arrow until we found the match. We simply return the first match we
|
||||
// find, so we have no way to assert that there are no duplicates.
|
||||
if matchIndex == -1 {
|
||||
self.GotoTop()
|
||||
matchIndex = len(lines)
|
||||
}
|
||||
|
||||
selectedLineIdx := self.getSelectedLineIdx()
|
||||
if selectedLineIdx == matchIndex {
|
||||
return self.SelectedLine(matcher)
|
||||
@@ -514,12 +519,14 @@ func (self *ViewDriver) NavigateToLine(matcher *TextMatcher) *ViewDriver {
|
||||
for i := 0; i < maxNumKeyPresses; i++ {
|
||||
keyPress()
|
||||
idx := self.getSelectedLineIdx()
|
||||
if ok, _ := matcher.test(lines[idx]); ok {
|
||||
// It is important to use view.BufferLines() here and not lines, because it
|
||||
// could change with every keypress.
|
||||
if ok, _ := matcher.test(view.BufferLines()[idx]); ok {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
self.t.fail(fmt.Sprintf("Could not navigate to item matching: %s. Lines:\n%s", matcher.name(), strings.Join(lines, "\n")))
|
||||
self.t.fail(fmt.Sprintf("Could not navigate to item matching: %s. Lines:\n%s", matcher.name(), strings.Join(view.BufferLines(), "\n")))
|
||||
return self
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user