mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-10-25 05:37:37 +03:00
So far, confirmations and prompts were handled by the same view, context, and controller, with a bunch of conditional code based on whether the view is editable. This was more or less ok so far, since it does save a little bit of code duplication; however, now we need separate views, because we don't have dynamic keybindings, but we want to map "confirm" to different keys in confirmations (the "universal.confirm" user config) and prompts (hard-coded to enter, because it doesn't make sense to customize it there). It also allows us to get rid of the conditional code, which is a nice benefit; and the code duplication is actually not *that* bad.
103 lines
2.4 KiB
Go
103 lines
2.4 KiB
Go
package components
|
|
|
|
type PromptDriver struct {
|
|
t *TestDriver
|
|
hasCheckedTitle bool
|
|
}
|
|
|
|
func (self *PromptDriver) getViewDriver() *ViewDriver {
|
|
return self.t.Views().Prompt()
|
|
}
|
|
|
|
// asserts that the popup has the expected title
|
|
func (self *PromptDriver) Title(expected *TextMatcher) *PromptDriver {
|
|
self.getViewDriver().Title(expected)
|
|
|
|
self.hasCheckedTitle = true
|
|
|
|
return self
|
|
}
|
|
|
|
// asserts on the text initially present in the prompt
|
|
func (self *PromptDriver) InitialText(expected *TextMatcher) *PromptDriver {
|
|
self.getViewDriver().Content(expected)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *PromptDriver) Type(value string) *PromptDriver {
|
|
self.t.typeContent(value)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *PromptDriver) Clear() *PromptDriver {
|
|
self.t.press(ClearKey)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *PromptDriver) Confirm() {
|
|
self.checkNecessaryChecksCompleted()
|
|
|
|
self.getViewDriver().PressEnter()
|
|
}
|
|
|
|
func (self *PromptDriver) Cancel() {
|
|
self.checkNecessaryChecksCompleted()
|
|
|
|
self.getViewDriver().PressEscape()
|
|
}
|
|
|
|
func (self *PromptDriver) checkNecessaryChecksCompleted() {
|
|
if !self.hasCheckedTitle {
|
|
self.t.Fail("You must check the title of a prompt popup by calling Title() before calling Confirm()/Cancel().")
|
|
}
|
|
}
|
|
|
|
func (self *PromptDriver) SuggestionLines(matchers ...*TextMatcher) *PromptDriver {
|
|
self.t.Views().Suggestions().Lines(matchers...)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *PromptDriver) SuggestionTopLines(matchers ...*TextMatcher) *PromptDriver {
|
|
self.t.Views().Suggestions().TopLines(matchers...)
|
|
|
|
return self
|
|
}
|
|
|
|
func (self *PromptDriver) ConfirmFirstSuggestion() {
|
|
self.t.press(self.t.keys.Universal.TogglePanel)
|
|
self.t.Views().Suggestions().
|
|
IsFocused().
|
|
SelectedLineIdx(0).
|
|
PressEnter()
|
|
}
|
|
|
|
func (self *PromptDriver) ConfirmSuggestion(matcher *TextMatcher) {
|
|
self.t.press(self.t.keys.Universal.TogglePanel)
|
|
self.t.Views().Suggestions().
|
|
IsFocused().
|
|
NavigateToLine(matcher).
|
|
PressEnter()
|
|
}
|
|
|
|
func (self *PromptDriver) DeleteSuggestion(matcher *TextMatcher) *PromptDriver {
|
|
self.t.press(self.t.keys.Universal.TogglePanel)
|
|
self.t.Views().Suggestions().
|
|
IsFocused().
|
|
NavigateToLine(matcher)
|
|
self.t.press(self.t.keys.Universal.Remove)
|
|
return self
|
|
}
|
|
|
|
func (self *PromptDriver) EditSuggestion(matcher *TextMatcher) *PromptDriver {
|
|
self.t.press(self.t.keys.Universal.TogglePanel)
|
|
self.t.Views().Suggestions().
|
|
IsFocused().
|
|
NavigateToLine(matcher)
|
|
self.t.press(self.t.keys.Universal.Edit)
|
|
return self
|
|
}
|