Only apply right-alignment on first column of keybindings menu (#2801)

This commit is contained in:
Jesse Duffield 2023-07-20 21:27:01 +10:00 committed by GitHub
commit 6e247c1583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 16 deletions

View file

@ -14,7 +14,7 @@ type ListContextTrait struct {
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 getColumnAlignments func() []utils.Alignment
// Some contexts, like the commit context, will highlight the path from the selected commit // 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 // to its parents, because it's ambiguous otherwise. For these, we need to refresh the viewport
// so that we show the highlighted path. // 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 // 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 { func (self *ListContextTrait) HandleRender() error {
self.list.RefreshSelectedIdx() self.list.RefreshSelectedIdx()
var columnAlignments []utils.Alignment
if self.getColumnAlignments != nil {
columnAlignments = self.getColumnAlignments()
}
content := utils.RenderDisplayStrings( content := utils.RenderDisplayStrings(
self.getDisplayStrings(0, self.list.Len()), self.getDisplayStrings(0, self.list.Len()),
self.columnAlignments, columnAlignments,
) )
self.GetViewTrait().SetContent(content) self.GetViewTrait().SetContent(content)
self.c.Render() self.c.Render()

View file

@ -35,10 +35,10 @@ func NewMenuContext(
Focusable: true, Focusable: true,
HasUncontrolledBounds: true, HasUncontrolledBounds: true,
})), })),
getDisplayStrings: viewModel.GetDisplayStrings, getDisplayStrings: viewModel.GetDisplayStrings,
list: viewModel, list: viewModel,
c: c, c: c,
columnAlignments: []utils.Alignment{utils.AlignRight, utils.AlignLeft}, getColumnAlignments: func() []utils.Alignment { return viewModel.columnAlignment },
}, },
} }
} }
@ -54,8 +54,9 @@ func (self *MenuContext) GetSelectedItemId() string {
} }
type MenuViewModel struct { type MenuViewModel struct {
c *ContextCommon c *ContextCommon
menuItems []*types.MenuItem menuItems []*types.MenuItem
columnAlignment []utils.Alignment
*FilteredListViewModel[*types.MenuItem] *FilteredListViewModel[*types.MenuItem]
} }
@ -73,8 +74,9 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
return self return self
} }
func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem) { func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem, columnAlignment []utils.Alignment) {
self.menuItems = items self.menuItems = items
self.columnAlignment = columnAlignment
} }
// TODO: move into presentation package // TODO: move into presentation package

View file

@ -4,6 +4,7 @@ import (
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo" "github.com/samber/lo"
) )
@ -37,9 +38,10 @@ func (self *OptionsMenuAction) Call() error {
}) })
return self.c.Menu(types.CreateMenuOptions{ return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.Keybindings, Title: self.c.Tr.Keybindings,
Items: menuItems, Items: menuItems,
HideCancel: true, HideCancel: true,
ColumnAlignment: []utils.Alignment{utils.AlignRight, utils.AlignLeft},
}) })
} }

View file

@ -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.State.Contexts.Menu.SetSelectedLineIdx(0)
gui.Views.Menu.Title = opts.Title gui.Views.Menu.Title = opts.Title

View file

@ -133,9 +133,10 @@ type IPopupHandler interface {
} }
type CreateMenuOptions struct { type CreateMenuOptions struct {
Title string Title string
Items []*MenuItem Items []*MenuItem
HideCancel bool HideCancel bool
ColumnAlignment []utils.Alignment
} }
type CreatePopupPanelOpts struct { type CreatePopupPanelOpts struct {