summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-06-06 16:54:27 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-06-23 11:54:21 +0200
commitdd2bffc278dc3879e112caa3effd9c9c426489af (patch)
tree6e48b8f181b687eaecf275c845e6a5adbcc05c81 /pkg
parent9eb9b369ffc7c99854e2565da9996c3dcc6116c8 (diff)
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.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/context/list_context_trait.go16
1 files changed, 3 insertions, 13 deletions
diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go
index c0e5ca04f..78d524bb2 100644
--- a/pkg/gui/context/list_context_trait.go
+++ b/pkg/gui/context/list_context_trait.go
@@ -25,10 +25,9 @@ func (self *ListContextTrait) IsListContext() {}
func (self *ListContextTrait) FocusLine() {
// Doing this at the end of the layout function because we need the view to be
// resized before we focus the line, otherwise if we're in accordion mode
- // the view could be squashed and won't how to adjust the cursor/origin
+ // the view could be squashed and won't how to adjust the cursor/origin.
+ // Also, refreshing the viewport needs to happen after the view has been resized.
self.c.AfterLayout(func() error {
- oldOrigin, _ := self.GetViewTrait().ViewPortYBounds()
-
self.GetViewTrait().FocusPoint(
self.ModelIndexToViewIndex(self.list.GetSelectedLineIdx()))
@@ -40,22 +39,13 @@ func (self *ListContextTrait) FocusLine() {
self.GetViewTrait().CancelRangeSelect()
}
- // If FocusPoint() caused the view to scroll (because the selected line
- // was out of view before), we need to rerender the view port again.
- // This can happen when pressing , or . to scroll by pages, or < or > to
- // jump to the top or bottom.
- newOrigin, _ := self.GetViewTrait().ViewPortYBounds()
- if self.refreshViewportOnChange && oldOrigin != newOrigin {
+ if self.refreshViewportOnChange {
self.refreshViewport()
}
return nil
})
self.setFooter()
-
- if self.refreshViewportOnChange {
- self.refreshViewport()
- }
}
func (self *ListContextTrait) refreshViewport() {