mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-03 15:02:52 +02:00
When we use the one panel for the entire commit message, its tricky to have a keybinding both for adding a newline and submitting. By having two panels: one for the summary line and one for the description, we allow for 'enter' to submit the message when done from the summary panel, and 'enter' to add a newline when done from the description panel. Alt-enter, for those who can use that key combo, also works for submitting the message from the description panel. For those who can't use that key combo, and don't want to remap the keybinding, they can hit tab to go back to the summary panel and then 'enter' to submit the message. We have some awkwardness in that both contexts (i.e. panels) need to appear and disappear in tandem and we don't have a great way of handling that concept, so we just push both contexts one after the other, and likewise remove both contexts when we escape.
109 lines
2.8 KiB
Go
109 lines
2.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
// hacking this by including the gui struct for now until we split more things out
|
|
type guiCommon struct {
|
|
gui *Gui
|
|
types.IPopupHandler
|
|
}
|
|
|
|
var _ types.IGuiCommon = &guiCommon{}
|
|
|
|
func (self *guiCommon) LogAction(msg string) {
|
|
self.gui.LogAction(msg)
|
|
}
|
|
|
|
func (self *guiCommon) LogCommand(cmdStr string, isCommandLine bool) {
|
|
self.gui.LogCommand(cmdStr, isCommandLine)
|
|
}
|
|
|
|
func (self *guiCommon) Refresh(opts types.RefreshOptions) error {
|
|
return self.gui.Refresh(opts)
|
|
}
|
|
|
|
func (self *guiCommon) PostRefreshUpdate(context types.Context) error {
|
|
return self.gui.postRefreshUpdate(context)
|
|
}
|
|
|
|
func (self *guiCommon) RunSubprocessAndRefresh(cmdObj oscommands.ICmdObj) error {
|
|
return self.gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
|
|
}
|
|
|
|
func (self *guiCommon) RunSubprocess(cmdObj oscommands.ICmdObj) (bool, error) {
|
|
return self.gui.runSubprocessWithSuspense(cmdObj)
|
|
}
|
|
|
|
func (self *guiCommon) PushContext(context types.Context, opts ...types.OnFocusOpts) error {
|
|
singleOpts := types.OnFocusOpts{}
|
|
if len(opts) > 0 {
|
|
// using triple dot but you should only ever pass one of these opt structs
|
|
if len(opts) > 1 {
|
|
return errors.New("cannot pass multiple opts to pushContext")
|
|
}
|
|
|
|
singleOpts = opts[0]
|
|
}
|
|
|
|
return self.gui.pushContext(context, singleOpts)
|
|
}
|
|
|
|
func (self *guiCommon) PopContext() error {
|
|
return self.gui.popContext()
|
|
}
|
|
|
|
func (self *guiCommon) RemoveContexts(contexts []types.Context) error {
|
|
return self.gui.removeContexts(contexts)
|
|
}
|
|
|
|
func (self *guiCommon) CurrentContext() types.Context {
|
|
return self.gui.currentContext()
|
|
}
|
|
|
|
func (self *guiCommon) CurrentStaticContext() types.Context {
|
|
return self.gui.currentStaticContext()
|
|
}
|
|
|
|
func (self *guiCommon) IsCurrentContext(c types.Context) bool {
|
|
return self.CurrentContext().GetKey() == c.GetKey()
|
|
}
|
|
|
|
func (self *guiCommon) GetAppState() *config.AppState {
|
|
return self.gui.Config.GetAppState()
|
|
}
|
|
|
|
func (self *guiCommon) SaveAppState() error {
|
|
return self.gui.Config.SaveAppState()
|
|
}
|
|
|
|
func (self *guiCommon) Render() {
|
|
self.gui.render()
|
|
}
|
|
|
|
func (self *guiCommon) OpenSearch() {
|
|
_ = self.gui.handleOpenSearch(self.gui.currentViewName())
|
|
}
|
|
|
|
func (self *guiCommon) OnUIThread(f func() error) {
|
|
self.gui.onUIThread(f)
|
|
}
|
|
|
|
func (self *guiCommon) RenderToMainViews(opts types.RefreshMainOpts) error {
|
|
return self.gui.refreshMainViews(opts)
|
|
}
|
|
|
|
func (self *guiCommon) MainViewPairs() types.MainViewPairs {
|
|
return types.MainViewPairs{
|
|
Normal: self.gui.normalMainContextPair(),
|
|
Staging: self.gui.stagingMainContextPair(),
|
|
PatchBuilding: self.gui.patchBuildingMainContextPair(),
|
|
MergeConflicts: self.gui.mergingMainContextPair(),
|
|
}
|
|
}
|