Skip to content

Commit dd2bffc

Browse files
committed
Simplify ListContextTrait.FocusLine
When refreshViewportOnChange is true, we would refresh the viewport once at the end of FocusLine, and then we would check at the end of AfterLayout if the origin has changed, and refresh again if so. That's unnecessarily complicated, let's just unconditionally refresh at the end of AfterLayout only.
1 parent 9eb9b36 commit dd2bffc

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

pkg/gui/context/list_context_trait.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ func (self *ListContextTrait) IsListContext() {}
2525
func (self *ListContextTrait) FocusLine() {
2626
// Doing this at the end of the layout function because we need the view to be
2727
// resized before we focus the line, otherwise if we're in accordion mode
28-
// the view could be squashed and won't how to adjust the cursor/origin
28+
// the view could be squashed and won't how to adjust the cursor/origin.
29+
// Also, refreshing the viewport needs to happen after the view has been resized.
2930
self.c.AfterLayout(func() error {
30-
oldOrigin, _ := self.GetViewTrait().ViewPortYBounds()
31-
3231
self.GetViewTrait().FocusPoint(
3332
self.ModelIndexToViewIndex(self.list.GetSelectedLineIdx()))
3433

@@ -40,22 +39,13 @@ func (self *ListContextTrait) FocusLine() {
4039
self.GetViewTrait().CancelRangeSelect()
4140
}
4241

43-
// If FocusPoint() caused the view to scroll (because the selected line
44-
// was out of view before), we need to rerender the view port again.
45-
// This can happen when pressing , or . to scroll by pages, or < or > to
46-
// jump to the top or bottom.
47-
newOrigin, _ := self.GetViewTrait().ViewPortYBounds()
48-
if self.refreshViewportOnChange && oldOrigin != newOrigin {
42+
if self.refreshViewportOnChange {
4943
self.refreshViewport()
5044
}
5145
return nil
5246
})
5347

5448
self.setFooter()
55-
56-
if self.refreshViewportOnChange {
57-
self.refreshViewport()
58-
}
5949
}
6050

6151
func (self *ListContextTrait) refreshViewport() {

0 commit comments

Comments
 (0)