Skip to content

Commit 14187c9

Browse files
authored
More navigation keybindings for confirmation panel (#4404)
- **PR Description** Add bindings for `,` (page up), `.` (page down), `<` or `<home>` (top), and `>` or `<end>` (bottom), for scrolling long text in confirmation panels. This is useful for example for git hooks that output a lot of error text on failure, where the most interesting bit of information is probably at the end. I chose not to bind `<pgUp>` and `<pgDown>`, since they are normally used for scrolling the main view. Which is not a thing when a confirmation is shown or the Extras panel is focused, so we *could* use them in these cases, but I thought it might be confusing when they are used for different things in different contexts. While we're at it, add the same navigation bindings also to the Extras panel (i.e. the command log when it has the focus). Fixes #4372. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents ed0cc8b + 8a45060 commit 14187c9

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

pkg/gui/extras_panel.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,38 @@ func (gui *Gui) scrollDownExtra() error {
5858
return nil
5959
}
6060

61+
func (gui *Gui) pageUpExtrasPanel() error {
62+
gui.Views.Extras.Autoscroll = false
63+
64+
gui.Views.Extras.ScrollUp(gui.Contexts().CommandLog.GetViewTrait().PageDelta())
65+
66+
return nil
67+
}
68+
69+
func (gui *Gui) pageDownExtrasPanel() error {
70+
gui.Views.Extras.Autoscroll = false
71+
72+
gui.Views.Extras.ScrollDown(gui.Contexts().CommandLog.GetViewTrait().PageDelta())
73+
74+
return nil
75+
}
76+
77+
func (gui *Gui) goToExtrasPanelTop() error {
78+
gui.Views.Extras.Autoscroll = false
79+
80+
gui.Views.Extras.ScrollUp(gui.Views.Extras.ViewLinesHeight())
81+
82+
return nil
83+
}
84+
85+
func (gui *Gui) goToExtrasPanelBottom() error {
86+
gui.Views.Extras.Autoscroll = true
87+
88+
gui.Views.Extras.ScrollDown(gui.Views.Extras.ViewLinesHeight())
89+
90+
return nil
91+
}
92+
6193
func (gui *Gui) getCmdWriter() io.Writer {
6294
return &prefixWriter{writer: gui.Views.Extras, prefix: style.FgMagenta.Sprintf("\n\n%s\n", gui.c.Tr.GitOutput)}
6395
}

pkg/gui/global_handlers.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,46 @@ func (gui *Gui) scrollDownConfirmationPanel() error {
109109
return nil
110110
}
111111

112+
func (gui *Gui) pageUpConfirmationPanel() error {
113+
if gui.Views.Confirmation.Editable {
114+
return nil
115+
}
116+
117+
gui.Views.Confirmation.ScrollUp(gui.Contexts().Confirmation.GetViewTrait().PageDelta())
118+
119+
return nil
120+
}
121+
122+
func (gui *Gui) pageDownConfirmationPanel() error {
123+
if gui.Views.Confirmation.Editable {
124+
return nil
125+
}
126+
127+
gui.Views.Confirmation.ScrollDown(gui.Contexts().Confirmation.GetViewTrait().PageDelta())
128+
129+
return nil
130+
}
131+
132+
func (gui *Gui) goToConfirmationPanelTop() error {
133+
if gui.Views.Confirmation.Editable {
134+
return nil
135+
}
136+
137+
gui.Views.Confirmation.ScrollUp(gui.Views.Confirmation.ViewLinesHeight())
138+
139+
return nil
140+
}
141+
142+
func (gui *Gui) goToConfirmationPanelBottom() error {
143+
if gui.Views.Confirmation.Editable {
144+
return nil
145+
}
146+
147+
gui.Views.Confirmation.ScrollDown(gui.Views.Confirmation.ViewLinesHeight())
148+
149+
return nil
150+
}
151+
112152
func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
113153
return gui.handleCopySelectedSideContextItemToClipboardWithTruncation(-1)
114154
}

pkg/gui/keybindings.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,42 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
260260
Key: gocui.MouseWheelDown,
261261
Handler: self.scrollDownConfirmationPanel,
262262
},
263+
{
264+
ViewName: "confirmation",
265+
Key: opts.GetKey(opts.Config.Universal.NextPage),
266+
Modifier: gocui.ModNone,
267+
Handler: self.pageDownConfirmationPanel,
268+
},
269+
{
270+
ViewName: "confirmation",
271+
Key: opts.GetKey(opts.Config.Universal.PrevPage),
272+
Modifier: gocui.ModNone,
273+
Handler: self.pageUpConfirmationPanel,
274+
},
275+
{
276+
ViewName: "confirmation",
277+
Key: opts.GetKey(opts.Config.Universal.GotoTop),
278+
Modifier: gocui.ModNone,
279+
Handler: self.goToConfirmationPanelTop,
280+
},
281+
{
282+
ViewName: "confirmation",
283+
Key: opts.GetKey(opts.Config.Universal.GotoTopAlt),
284+
Modifier: gocui.ModNone,
285+
Handler: self.goToConfirmationPanelTop,
286+
},
287+
{
288+
ViewName: "confirmation",
289+
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
290+
Modifier: gocui.ModNone,
291+
Handler: self.goToConfirmationPanelBottom,
292+
},
293+
{
294+
ViewName: "confirmation",
295+
Key: opts.GetKey(opts.Config.Universal.GotoBottomAlt),
296+
Modifier: gocui.ModNone,
297+
Handler: self.goToConfirmationPanelBottom,
298+
},
263299
{
264300
ViewName: "submodules",
265301
Key: opts.GetKey(opts.Config.Universal.CopyToClipboard),
@@ -305,6 +341,42 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
305341
Modifier: gocui.ModNone,
306342
Handler: self.scrollDownExtra,
307343
},
344+
{
345+
ViewName: "extras",
346+
Key: opts.GetKey(opts.Config.Universal.NextPage),
347+
Modifier: gocui.ModNone,
348+
Handler: self.pageDownExtrasPanel,
349+
},
350+
{
351+
ViewName: "extras",
352+
Key: opts.GetKey(opts.Config.Universal.PrevPage),
353+
Modifier: gocui.ModNone,
354+
Handler: self.pageUpExtrasPanel,
355+
},
356+
{
357+
ViewName: "extras",
358+
Key: opts.GetKey(opts.Config.Universal.GotoTop),
359+
Modifier: gocui.ModNone,
360+
Handler: self.goToExtrasPanelTop,
361+
},
362+
{
363+
ViewName: "extras",
364+
Key: opts.GetKey(opts.Config.Universal.GotoTopAlt),
365+
Modifier: gocui.ModNone,
366+
Handler: self.goToExtrasPanelTop,
367+
},
368+
{
369+
ViewName: "extras",
370+
Key: opts.GetKey(opts.Config.Universal.GotoBottom),
371+
Modifier: gocui.ModNone,
372+
Handler: self.goToExtrasPanelBottom,
373+
},
374+
{
375+
ViewName: "extras",
376+
Key: opts.GetKey(opts.Config.Universal.GotoBottomAlt),
377+
Modifier: gocui.ModNone,
378+
Handler: self.goToExtrasPanelBottom,
379+
},
308380
{
309381
ViewName: "extras",
310382
Tag: "navigation",

0 commit comments

Comments
 (0)