mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
Merge pull request #2670 from jesseduffield/better-list-context-trait
This commit is contained in:
commit
be6acf2fbe
@ -13,8 +13,15 @@ type ListContextTrait struct {
|
|||||||
c *ContextCommon
|
c *ContextCommon
|
||||||
list types.IList
|
list types.IList
|
||||||
getDisplayStrings func(startIdx int, length int) [][]string
|
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
|
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() {}
|
func (self *ListContextTrait) IsListContext() {}
|
||||||
@ -24,9 +31,19 @@ func (self *ListContextTrait) GetList() types.IList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *ListContextTrait) FocusLine() {
|
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.GetViewTrait().FocusPoint(self.list.GetSelectedLineIdx())
|
||||||
self.setFooter()
|
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() {
|
func (self *ListContextTrait) setFooter() {
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
type LocalCommitsContext struct {
|
type LocalCommitsContext struct {
|
||||||
*LocalCommitsViewModel
|
*LocalCommitsViewModel
|
||||||
*ViewportListContextTrait
|
*ListContextTrait
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -56,19 +56,18 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
|
|||||||
|
|
||||||
return &LocalCommitsContext{
|
return &LocalCommitsContext{
|
||||||
LocalCommitsViewModel: viewModel,
|
LocalCommitsViewModel: viewModel,
|
||||||
ViewportListContextTrait: &ViewportListContextTrait{
|
ListContextTrait: &ListContextTrait{
|
||||||
ListContextTrait: &ListContextTrait{
|
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
||||||
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
View: c.Views().Commits,
|
||||||
View: c.Views().Commits,
|
WindowName: "commits",
|
||||||
WindowName: "commits",
|
Key: LOCAL_COMMITS_CONTEXT_KEY,
|
||||||
Key: LOCAL_COMMITS_CONTEXT_KEY,
|
Kind: types.SIDE_CONTEXT,
|
||||||
Kind: types.SIDE_CONTEXT,
|
Focusable: true,
|
||||||
Focusable: true,
|
})),
|
||||||
})),
|
list: viewModel,
|
||||||
list: viewModel,
|
getDisplayStrings: getDisplayStrings,
|
||||||
getDisplayStrings: getDisplayStrings,
|
c: c,
|
||||||
c: c,
|
refreshViewportOnLineFocus: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type SubCommitsContext struct {
|
type SubCommitsContext struct {
|
||||||
*SubCommitsViewModel
|
*SubCommitsViewModel
|
||||||
*ViewportListContextTrait
|
*ListContextTrait
|
||||||
*DynamicTitleBuilder
|
*DynamicTitleBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,20 +60,19 @@ func NewSubCommitsContext(
|
|||||||
return &SubCommitsContext{
|
return &SubCommitsContext{
|
||||||
SubCommitsViewModel: viewModel,
|
SubCommitsViewModel: viewModel,
|
||||||
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.SubCommitsDynamicTitle),
|
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.SubCommitsDynamicTitle),
|
||||||
ViewportListContextTrait: &ViewportListContextTrait{
|
ListContextTrait: &ListContextTrait{
|
||||||
ListContextTrait: &ListContextTrait{
|
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
||||||
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
|
View: c.Views().SubCommits,
|
||||||
View: c.Views().SubCommits,
|
WindowName: "branches",
|
||||||
WindowName: "branches",
|
Key: SUB_COMMITS_CONTEXT_KEY,
|
||||||
Key: SUB_COMMITS_CONTEXT_KEY,
|
Kind: types.SIDE_CONTEXT,
|
||||||
Kind: types.SIDE_CONTEXT,
|
Focusable: true,
|
||||||
Focusable: true,
|
Transient: true,
|
||||||
Transient: true,
|
})),
|
||||||
})),
|
list: viewModel,
|
||||||
list: viewModel,
|
getDisplayStrings: getDisplayStrings,
|
||||||
getDisplayStrings: getDisplayStrings,
|
c: c,
|
||||||
c: c,
|
refreshViewportOnLineFocus: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user