summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/list_context_trait.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-25 17:09:18 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-05-25 17:09:18 +1000
commitadd1de413868a35ad1ace5c943104ba2269c528a (patch)
tree5a45a6382bb54edac6adf18b2f34faf620500006 /pkg/gui/context/list_context_trait.go
parent1f8e838052a1bc083cb50560431b2f115df8acb6 (diff)
Use boolean field to control whether viewport is refreshed on line focus
Go really doesn't like us doing anything inheritance-y: it does not support open recursion meaning it's really hard to re-use code. As such, here we're falling back to conditional logic. This fixes an issue where our ListContextTrait was calling FocusLine which was intended to be overridden by ViewportListContextTrait, but the subclassed function wasn't being called. I'm not actually sure how this went wrong given that it was working fine in the past, but at any rate, the new code is easy to follow.
Diffstat (limited to 'pkg/gui/context/list_context_trait.go')
-rw-r--r--pkg/gui/context/list_context_trait.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go
index 5dd9b50e0..e001bd3a7 100644
--- a/pkg/gui/context/list_context_trait.go
+++ b/pkg/gui/context/list_context_trait.go
@@ -13,8 +13,15 @@ type ListContextTrait struct {
c *ContextCommon
list types.IList
getDisplayStrings func(startIdx int, length int) [][]string
- // alignment for each column. If nil, the default is left alignment
+ // Alignment for each column. If nil, the default is left alignment
columnAlignments []utils.Alignment
+ // Some contexts, like the commit context, will highlight the path from the selected commit
+ // to its parents, because it's ambiguous otherwise. For these, we need to refresh the viewport
+ // so that we show the highlighted path.
+ // TODO: now that we allow scrolling, we should be smarter about what gets refreshed:
+ // 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.
+ refreshViewportOnLineFocus bool
}
func (self *ListContextTrait) IsListContext() {}
@@ -24,9 +31,19 @@ func (self *ListContextTrait) GetList() types.IList {
}
func (self *ListContextTrait) FocusLine() {
- // we need a way of knowing whether we've rendered to the view yet.
self.GetViewTrait().FocusPoint(self.list.GetSelectedLineIdx())
self.setFooter()
+
+ if self.refreshViewportOnLineFocus {
+ self.refreshViewport()
+ }
+}
+
+func (self *ListContextTrait) refreshViewport() {
+ startIdx, length := self.GetViewTrait().ViewPortYBounds()
+ displayStrings := self.getDisplayStrings(startIdx, length)
+ content := utils.RenderDisplayStrings(displayStrings, nil)
+ self.GetViewTrait().SetViewPortContent(content)
}
func (self *ListContextTrait) setFooter() {