summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/list_context_trait.go
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-03-30 18:17:50 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-06-23 11:54:21 +0200
commit44160ef8448239e397c7bddbbd78bc9cd38327a3 (patch)
treecfba440a269fa079f6d2eeb83f601bd9079ebe87 /pkg/gui/context/list_context_trait.go
parentdd2bffc278dc3879e112caa3effd9c9c426489af (diff)
Only render visible portion of the screen for commits view
Diffstat (limited to 'pkg/gui/context/list_context_trait.go')
-rw-r--r--pkg/gui/context/list_context_trait.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go
index 78d524bb2..aca33cbd0 100644
--- a/pkg/gui/context/list_context_trait.go
+++ b/pkg/gui/context/list_context_trait.go
@@ -18,6 +18,9 @@ type ListContextTrait struct {
// we should find out exactly which lines are now part of the path and refresh those.
// We should also keep track of the previous path and refresh those lines too.
refreshViewportOnChange bool
+ // If this is true, we only render the visible lines of the list. Useful for lists that can
+ // get very long, because it can save a lot of memory
+ renderOnlyVisibleLines bool
}
func (self *ListContextTrait) IsListContext() {}
@@ -28,6 +31,8 @@ func (self *ListContextTrait) FocusLine() {
// 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()))
@@ -41,6 +46,11 @@ func (self *ListContextTrait) FocusLine() {
if self.refreshViewportOnChange {
self.refreshViewport()
+ } else if self.renderOnlyVisibleLines {
+ newOrigin, _ := self.GetViewTrait().ViewPortYBounds()
+ if oldOrigin != newOrigin {
+ return self.HandleRender()
+ }
}
return nil
})
@@ -83,8 +93,21 @@ func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) error
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
func (self *ListContextTrait) HandleRender() error {
self.list.ClampSelection()
- content := self.renderLines(-1, -1)
- self.GetViewTrait().SetContent(content)
+ if self.renderOnlyVisibleLines {
+ // Rendering only the visible area can save a lot of cell memory for
+ // those views that support it.
+ totalLength := self.list.Len()
+ if self.getNonModelItems != nil {
+ totalLength += len(self.getNonModelItems())
+ }
+ self.GetViewTrait().SetContentLineCount(totalLength)
+ startIdx, length := self.GetViewTrait().ViewPortYBounds()
+ content := self.renderLines(startIdx, startIdx+length)
+ self.GetViewTrait().SetViewPortContentAndClearEverythingElse(content)
+ } else {
+ content := self.renderLines(-1, -1)
+ self.GetViewTrait().SetContent(content)
+ }
self.c.Render()
self.setFooter()