mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-05 13:24:54 +02:00
49da7b482d
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.
86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package components
|
|
|
|
type CommitMessagePanelDriver struct {
|
|
t *TestDriver
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) getViewDriver() *ViewDriver {
|
|
return self.t.Views().CommitMessage()
|
|
}
|
|
|
|
// asserts on the text initially present in the prompt
|
|
func (self *CommitMessagePanelDriver) InitialText(expected *Matcher) *CommitMessagePanelDriver {
|
|
return self.Content(expected)
|
|
}
|
|
|
|
// asserts on the current context in the prompt
|
|
func (self *CommitMessagePanelDriver) Content(expected *Matcher) *CommitMessagePanelDriver {
|
|
self.getViewDriver().Content(expected)
|
|
|
|
return self
|
|
}
|
|
|
|
// asserts that the confirmation view has the expected title
|
|
func (self *CommitMessagePanelDriver) Title(expected *Matcher) *CommitMessagePanelDriver {
|
|
self.getViewDriver().Title(expected)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) Type(value string) *CommitMessagePanelDriver {
|
|
self.t.typeContent(value)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) SwitchToDescription() *CommitDescriptionPanelDriver {
|
|
self.getViewDriver().PressTab()
|
|
return &CommitDescriptionPanelDriver{t: self.t}
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) AddNewline() *CommitMessagePanelDriver {
|
|
self.t.press(self.t.keys.Universal.Confirm)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) Clear() *CommitMessagePanelDriver {
|
|
// clearing multiple times in case there's multiple lines
|
|
// (the clear button only clears a single line at a time)
|
|
maxAttempts := 100
|
|
for i := 0; i < maxAttempts+1; i++ {
|
|
if self.getViewDriver().getView().Buffer() == "" {
|
|
break
|
|
}
|
|
|
|
self.t.press(ClearKey)
|
|
if i == maxAttempts {
|
|
panic("failed to clear commit message panel")
|
|
}
|
|
}
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) Confirm() {
|
|
self.getViewDriver().PressEnter()
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) Close() {
|
|
self.getViewDriver().PressEscape()
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) Cancel() {
|
|
self.getViewDriver().PressEscape()
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) SelectPreviousMessage() *CommitMessagePanelDriver {
|
|
self.getViewDriver().SelectPreviousItem()
|
|
return self
|
|
}
|
|
|
|
func (self *CommitMessagePanelDriver) SelectNextMessage() *CommitMessagePanelDriver {
|
|
self.getViewDriver().SelectNextItem()
|
|
return self
|
|
}
|