diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 68d68575e..8551d9f4e 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -53,14 +53,6 @@ func (self *ConfirmationHelper) wrappedPromptConfirmationFunction( preserveWhitespace bool, ) func() error { return func() error { - if self.c.GocuiGui().IsPasting { - // The user is pasting multi-line text into a prompt; we don't want to handle the - // line feeds as "confirm" keybindings. Simply ignoring them is the best we can do; this - // will cause the entire pasted text to appear as a single line in the prompt. Hopefully - // the user knows that ctrl-u allows them to delete it again... - return nil - } - response := getResponse() if !preserveWhitespace { response = strings.TrimSpace(response) diff --git a/pkg/gui/editors.go b/pkg/gui/editors.go index 6e4f3591b..53ec9c6b2 100644 --- a/pkg/gui/editors.go +++ b/pkg/gui/editors.go @@ -40,6 +40,13 @@ func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key) bool { return matched } +func (gui *Gui) pasteIntoPrompt(text string) { + v := gui.Views.Prompt + if typePastedTextIntoSingleLineView(v, text) { + gui.onPromptContentChanged(v) + } +} + func (gui *Gui) onPromptContentChanged(v *gocui.View) { suggestionsContext := gui.State.Contexts.Suggestions // Capture the suggestions function and the input here, on the UI thread; the diff --git a/pkg/gui/views.go b/pkg/gui/views.go index eb93d6db7..c7c648f94 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -140,6 +140,10 @@ func (gui *Gui) createAllViews() error { gui.Views.Prompt.Wrap = false // We don't want wrapping in one-line prompts gui.Views.Prompt.Editable = true gui.Views.Prompt.Editor = gocui.EditorFunc(gui.promptEditor) + gui.Views.Prompt.OnPaste = func(text string) error { + gui.pasteIntoPrompt(text) + return nil + } gui.Views.Suggestions.Visible = false diff --git a/pkg/integration/components/prompt_driver.go b/pkg/integration/components/prompt_driver.go index 1000af007..7f9aedaa4 100644 --- a/pkg/integration/components/prompt_driver.go +++ b/pkg/integration/components/prompt_driver.go @@ -31,6 +31,13 @@ func (self *PromptDriver) Type(value string) *PromptDriver { 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) diff --git a/pkg/integration/tests/misc/paste_into_prompt.go b/pkg/integration/tests/misc/paste_into_prompt.go new file mode 100644 index 000000000..0d1b3076f --- /dev/null +++ b/pkg/integration/tests/misc/paste_into_prompt.go @@ -0,0 +1,29 @@ +package misc + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var PasteIntoPrompt = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Paste multi-line text into a prompt", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("initial commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Press(keys.Universal.New) + + t.ExpectPopup().Prompt(). + Title(Contains("New branch name")). + Paste("\nmy\tnew\nbranch\n") + + t.Views().Prompt(). + IsFocused(). + Content(Equals("my new branch")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index cb53307b2..7b8c23905 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -580,6 +580,7 @@ var tests = []*components.IntegrationTest{ misc.DirenvUnloadsOnBlockedEnvrc, misc.FilterRecentRepos, misc.InitialOpen, + misc.PasteIntoPrompt, misc.RecentReposBranchColumn, misc.RecentReposColumnWidths, misc.RecentReposOnLaunch,