Files
lazygit/pkg/integration/components/prompt_driver.go
Stefan HallerandClaude Opus 5.5 417dea6381 Let prompts receive pasted text in one piece
Like a menu's filter, a prompt takes a single line of text, so treat
pasted text the same way. Before, the prompt ignored pasted newlines.
This joined the lines without a space. It also ran the keybindings for
other keys in the text, so a pasted Esc closed the prompt, and a pasted
tab switched to the suggestions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00

110 lines
2.6 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
}
// pastes the text the way a terminal does it
func (self *PromptDriver) Paste(text string) *PromptDriver {
self.t.paste(text)
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[0])
self.t.Views().Suggestions().
IsFocused().
SelectedLineIdx(0).
Press(self.t.keys.Universal.ConfirmSuggestion)
}
func (self *PromptDriver) ConfirmSuggestion(matcher *TextMatcher) {
self.t.press(self.t.keys.Universal.TogglePanel[0])
self.t.Views().Suggestions().
IsFocused().
NavigateToLine(matcher).
Press(self.t.keys.Universal.ConfirmSuggestion)
}
func (self *PromptDriver) DeleteSuggestion(matcher *TextMatcher) *PromptDriver {
self.t.press(self.t.keys.Universal.TogglePanel[0])
self.t.Views().Suggestions().
IsFocused().
NavigateToLine(matcher)
self.t.press(self.t.keys.Universal.Remove[0])
return self
}
func (self *PromptDriver) EditSuggestion(matcher *TextMatcher) *PromptDriver {
self.t.press(self.t.keys.Universal.TogglePanel[0])
self.t.Views().Suggestions().
IsFocused().
NavigateToLine(matcher)
self.t.press(self.t.keys.Universal.Edit[0])
return self
}