Check the line we start on when navigating to a list item

NavigateToLine looks for its target among the lines the view has
rendered. When a list is scrolled, the view holds only the part of it
that is on screen, so the target may not be among them. For that case
the helper jumps to the top of the list and walks down instead.

That walk presses a key before it looks, so it never sees the item it
starts on, which after jumping is the first item of the list. A target
sitting there is reported as missing. The shorter the terminal, the more
of a list is scrolled out of view and the more often that walk is
needed, so this surfaced once the demos began running in a 35 line
terminal.

Check the line the walk starts on before moving off it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 18:26:56 +02:00
co-authored by Claude Opus 5
parent 17e7ae9af6
commit c9db062642
@@ -904,6 +904,14 @@ func (self *ViewDriver) NavigateToLine(matcher *TextMatcher) *ViewDriver {
keyPress = func() { self.SelectPreviousItem() }
}
// The loop below only looks at the lines it moves onto, so the line we are
// starting from has to be checked here. After jumping to the top that line
// is the first item of the list, and for a list we had to scroll through
// it is a plausible target.
if ok, _ := matcher.test(view.BufferLines()[selectedLineIdx]); ok {
return self
}
for range maxNumKeyPresses {
keyPress()
idx := self.getSelectedLineIdx()