summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-20 21:27:01 +1000
committerGitHub <noreply@github.com>2023-07-20 21:27:01 +1000
commit6e247c1583d84b2a7e31e9a17fd57e08ae58e1b9 (patch)
tree514e0ea010c263762f2e47474cfb85ad144234d2
parent1f920ae6ba781d5862b8bd66084c2a75da3f3076 (diff)
parent87bf1dbc7f1b600635c38065127853cd71f1dc18 (diff)
Only apply right-alignment on first column of keybindings menu (#2801)v0.39.0
-rw-r--r--pkg/gui/context/list_context_trait.go8
-rw-r--r--pkg/gui/context/menu_context.go16
-rw-r--r--pkg/gui/controllers/options_menu_action.go8
-rw-r--r--pkg/gui/menu_panel.go2
-rw-r--r--pkg/gui/types/common.go7
5 files changed, 25 insertions, 16 deletions
diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go
index de88d3d3b..54e3ab9ea 100644
--- a/pkg/gui/context/list_context_trait.go
+++ b/pkg/gui/context/list_context_trait.go
@@ -14,7 +14,7 @@ type ListContextTrait struct {
list types.IList
getDisplayStrings func(startIdx int, length int) [][]string
// Alignment for each column. If nil, the default is left alignment
- columnAlignments []utils.Alignment
+ getColumnAlignments func() []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.
@@ -82,9 +82,13 @@ 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.RefreshSelectedIdx()
+ var columnAlignments []utils.Alignment
+ if self.getColumnAlignments != nil {
+ columnAlignments = self.getColumnAlignments()
+ }
content := utils.RenderDisplayStrings(
self.getDisplayStrings(0, self.list.Len()),
- self.columnAlignments,
+ columnAlignments,
)
self.GetViewTrait().SetContent(content)
self.c.Render()
diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go
index a353a4e0d..4a174c019 100644
--- a/pkg/gui/context/menu_context.go
+++ b/pkg/gui/context/menu_context.go
@@ -35,10 +35,10 @@ func NewMenuContext(
Focusable: true,
HasUncontrolledBounds: true,
})),
- getDisplayStrings: viewModel.GetDisplayStrings,
- list: viewModel,
- c: c,
- columnAlignments: []utils.Alignment{utils.AlignRight, utils.AlignLeft},
+ getDisplayStrings: viewModel.GetDisplayStrings,
+ list: viewModel,
+ c: c,
+ getColumnAlignments: func() []utils.Alignment { return viewModel.columnAlignment },
},
}
}
@@ -54,8 +54,9 @@ func (self *MenuContext) GetSelectedItemId() string {
}
type MenuViewModel struct {
- c *ContextCommon
- menuItems []*types.MenuItem
+ c *ContextCommon
+ menuItems []*types.MenuItem
+ columnAlignment []utils.Alignment
*FilteredListViewModel[*types.MenuItem]
}
@@ -73,8 +74,9 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
return self
}
-func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem) {
+func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem, columnAlignment []utils.Alignment) {
self.menuItems = items
+ self.columnAlignment = columnAlignment
}
// TODO: move into presentation package
diff --git a/pkg/gui/controllers/options_menu_action.go b/pkg/gui/controllers/options_menu_action.go
index 1dfe3e8e0..7ec75d3f1 100644
--- a/pkg/gui/controllers/options_menu_action.go
+++ b/pkg/gui/controllers/options_menu_action.go
@@ -4,6 +4,7 @@ import (
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
+ "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
)
@@ -37,9 +38,10 @@ func (self *OptionsMenuAction) Call() error {
})
return self.c.Menu(types.CreateMenuOptions{
- Title: self.c.Tr.Keybindings,
- Items: menuItems,
- HideCancel: true,
+ Title: self.c.Tr.Keybindings,
+ Items: menuItems,
+ HideCancel: true,
+ ColumnAlignment: []utils.Alignment{utils.AlignRight, utils.AlignLeft},
})
}
diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go
index 19c58b145..9f3b3a55d 100644
--- a/pkg/gui/menu_panel.go
+++ b/pkg/gui/menu_panel.go
@@ -41,7 +41,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
}
}
- gui.State.Contexts.Menu.SetMenuItems(opts.Items)
+ gui.State.Contexts.Menu.SetMenuItems(opts.Items, opts.ColumnAlignment)
gui.State.Contexts.Menu.SetSelectedLineIdx(0)
gui.Views.Menu.Title = opts.Title
diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go
index 02dee3b15..33b0f7a18 100644
--- a/pkg/gui/types/common.go
+++ b/pkg/gui/types/common.go
@@ -133,9 +133,10 @@ type IPopupHandler interface {
}
type CreateMenuOptions struct {
- Title string
- Items []*MenuItem
- HideCancel bool
+ Title string
+ Items []*MenuItem
+ HideCancel bool
+ ColumnAlignment []utils.Alignment
}
type CreatePopupPanelOpts struct {