summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-26 15:28:32 +1000
committerGitHub <noreply@github.com>2023-05-26 15:28:32 +1000
commitbe6acf2fbe76fec606c48f1b0bd3904cc83d0315 (patch)
treeb8b450beff9f5b59c21d8c96755f3bc22e182464 /pkg
parentbf092f76d605a80b4e20d4ec2675644a237e3c49 (diff)
parentadd1de413868a35ad1ace5c943104ba2269c528a (diff)
Merge pull request #2670 from jesseduffield/better-list-context-trait
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/context/list_context_trait.go21
-rw-r--r--pkg/gui/context/local_commits_context.go27
-rw-r--r--pkg/gui/context/sub_commits_context.go29
-rw-r--r--pkg/gui/context/viewport_list_context_trait.go22
4 files changed, 46 insertions, 53 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() {
diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go
index e8ae0b6c5..efd175f98 100644
--- a/pkg/gui/context/local_commits_context.go
+++ b/pkg/gui/context/local_commits_context.go
@@ -11,7 +11,7 @@ import (
type LocalCommitsContext struct {
*LocalCommitsViewModel
- *ViewportListContextTrait
+ *ListContextTrait
}
var (
@@ -56,19 +56,18 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
return &LocalCommitsContext{
LocalCommitsViewModel: viewModel,
- ViewportListContextTrait: &ViewportListContextTrait{
- ListContextTrait: &ListContextTrait{
- Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- View: c.Views().Commits,
- WindowName: "commits",
- Key: LOCAL_COMMITS_CONTEXT_KEY,
- Kind: types.SIDE_CONTEXT,
- Focusable: true,
- })),
- list: viewModel,
- getDisplayStrings: getDisplayStrings,
- c: c,
- },
+ ListContextTrait: &ListContextTrait{
+ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
+ View: c.Views().Commits,
+ WindowName: "commits",
+ Key: LOCAL_COMMITS_CONTEXT_KEY,
+ Kind: types.SIDE_CONTEXT,
+ Focusable: true,
+ })),
+ list: viewModel,
+ getDisplayStrings: getDisplayStrings,
+ c: c,
+ refreshViewportOnLineFocus: true,
},
}
}
diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go
index 16712f982..a4d4205d1 100644
--- a/pkg/gui/context/sub_commits_context.go
+++ b/pkg/gui/context/sub_commits_context.go
@@ -12,7 +12,7 @@ import (
type SubCommitsContext struct {
*SubCommitsViewModel
- *ViewportListContextTrait
+ *ListContextTrait
*DynamicTitleBuilder
}
@@ -60,20 +60,19 @@ func NewSubCommitsContext(
return &SubCommitsContext{
SubCommitsViewModel: viewModel,
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.SubCommitsDynamicTitle),
- ViewportListContextTrait: &ViewportListContextTrait{
- ListContextTrait: &ListContextTrait{
- Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- View: c.Views().SubCommits,
- WindowName: "branches",
- Key: SUB_COMMITS_CONTEXT_KEY,
- Kind: types.SIDE_CONTEXT,
- Focusable: true,
- Transient: true,
- })),
- list: viewModel,
- getDisplayStrings: getDisplayStrings,
- c: c,
- },
+ ListContextTrait: &ListContextTrait{
+ Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
+ View: c.Views().SubCommits,
+ WindowName: "branches",
+ Key: SUB_COMMITS_CONTEXT_KEY,
+ Kind: types.SIDE_CONTEXT,
+ Focusable: true,
+ Transient: true,
+ })),
+ list: viewModel,
+ getDisplayStrings: getDisplayStrings,
+ c: c,
+ refreshViewportOnLineFocus: true,
},
}
}
diff --git a/pkg/gui/context/viewport_list_context_trait.go b/pkg/gui/context/viewport_list_context_trait.go
deleted file mode 100644
index 120e9f967..000000000
--- a/pkg/gui/context/viewport_list_context_trait.go
+++ /dev/null
@@ -1,22 +0,0 @@
-package context
-
-import (
- "github.com/jesseduffield/lazygit/pkg/utils"
-)
-
-// This embeds a list context trait and adds logic to re-render the viewport
-// whenever a line is focused. We use this in the commits panel because different
-// sections of the log graph need to be highlighted depending on the currently selected line
-
-type ViewportListContextTrait struct {
- *ListContextTrait
-}
-
-func (self *ViewportListContextTrait) FocusLine() {
- self.ListContextTrait.FocusLine()
-
- startIdx, length := self.GetViewTrait().ViewPortYBounds()
- displayStrings := self.ListContextTrait.getDisplayStrings(startIdx, length)
- content := utils.RenderDisplayStrings(displayStrings, nil)
- self.GetViewTrait().SetViewPortContent(content)
-}