Skip to content

Commit 87bf1db

Browse files
committed
Only apply right-alignment on first column of keybindings menu
Previously we applied a right-align on the first column of _all_ menus, even though we really only intended for it to be on the first column of the keybindings menu (that you get from pressing '?')
1 parent 1f920ae commit 87bf1db

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

pkg/gui/context/list_context_trait.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type ListContextTrait struct {
1414
list types.IList
1515
getDisplayStrings func(startIdx int, length int) [][]string
1616
// Alignment for each column. If nil, the default is left alignment
17-
columnAlignments []utils.Alignment
17+
getColumnAlignments func() []utils.Alignment
1818
// Some contexts, like the commit context, will highlight the path from the selected commit
1919
// to its parents, because it's ambiguous otherwise. For these, we need to refresh the viewport
2020
// so that we show the highlighted path.
@@ -82,9 +82,13 @@ func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) error
8282
// 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
8383
func (self *ListContextTrait) HandleRender() error {
8484
self.list.RefreshSelectedIdx()
85+
var columnAlignments []utils.Alignment
86+
if self.getColumnAlignments != nil {
87+
columnAlignments = self.getColumnAlignments()
88+
}
8589
content := utils.RenderDisplayStrings(
8690
self.getDisplayStrings(0, self.list.Len()),
87-
self.columnAlignments,
91+
columnAlignments,
8892
)
8993
self.GetViewTrait().SetContent(content)
9094
self.c.Render()

pkg/gui/context/menu_context.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func NewMenuContext(
3535
Focusable: true,
3636
HasUncontrolledBounds: true,
3737
})),
38-
getDisplayStrings: viewModel.GetDisplayStrings,
39-
list: viewModel,
40-
c: c,
41-
columnAlignments: []utils.Alignment{utils.AlignRight, utils.AlignLeft},
38+
getDisplayStrings: viewModel.GetDisplayStrings,
39+
list: viewModel,
40+
c: c,
41+
getColumnAlignments: func() []utils.Alignment { return viewModel.columnAlignment },
4242
},
4343
}
4444
}
@@ -54,8 +54,9 @@ func (self *MenuContext) GetSelectedItemId() string {
5454
}
5555

5656
type MenuViewModel struct {
57-
c *ContextCommon
58-
menuItems []*types.MenuItem
57+
c *ContextCommon
58+
menuItems []*types.MenuItem
59+
columnAlignment []utils.Alignment
5960
*FilteredListViewModel[*types.MenuItem]
6061
}
6162

@@ -73,8 +74,9 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
7374
return self
7475
}
7576

76-
func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem) {
77+
func (self *MenuViewModel) SetMenuItems(items []*types.MenuItem, columnAlignment []utils.Alignment) {
7778
self.menuItems = items
79+
self.columnAlignment = columnAlignment
7880
}
7981

8082
// TODO: move into presentation package

pkg/gui/controllers/options_menu_action.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/jesseduffield/generics/slices"
55
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
66
"github.com/jesseduffield/lazygit/pkg/gui/types"
7+
"github.com/jesseduffield/lazygit/pkg/utils"
78
"github.com/samber/lo"
89
)
910

@@ -37,9 +38,10 @@ func (self *OptionsMenuAction) Call() error {
3738
})
3839

3940
return self.c.Menu(types.CreateMenuOptions{
40-
Title: self.c.Tr.Keybindings,
41-
Items: menuItems,
42-
HideCancel: true,
41+
Title: self.c.Tr.Keybindings,
42+
Items: menuItems,
43+
HideCancel: true,
44+
ColumnAlignment: []utils.Alignment{utils.AlignRight, utils.AlignLeft},
4345
})
4446
}
4547

pkg/gui/menu_panel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
4141
}
4242
}
4343

44-
gui.State.Contexts.Menu.SetMenuItems(opts.Items)
44+
gui.State.Contexts.Menu.SetMenuItems(opts.Items, opts.ColumnAlignment)
4545
gui.State.Contexts.Menu.SetSelectedLineIdx(0)
4646

4747
gui.Views.Menu.Title = opts.Title

pkg/gui/types/common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ type IPopupHandler interface {
133133
}
134134

135135
type CreateMenuOptions struct {
136-
Title string
137-
Items []*MenuItem
138-
HideCancel bool
136+
Title string
137+
Items []*MenuItem
138+
HideCancel bool
139+
ColumnAlignment []utils.Alignment
139140
}
140141

141142
type CreatePopupPanelOpts struct {

0 commit comments

Comments
 (0)