From 9765b9679017a0da319b275699636964e45c4c90 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 12 Nov 2026 09:14:27 +0100 Subject: [PATCH] Let the search prompt receive pasted text in one piece Treat pasted text like in the other views that take a single line of text. Before, a pasted newline confirmed the search, and the rest of the pasted text was lost. Co-Authored-By: Claude Opus 5.5 --- pkg/gui/editors.go | 7 +++ pkg/gui/views.go | 4 ++ pkg/integration/components/search_driver.go | 7 +++ .../paste_into_search_prompt.go | 49 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 5 files changed, 68 insertions(+) create mode 100644 pkg/integration/tests/filter_and_search/paste_into_search_prompt.go diff --git a/pkg/gui/editors.go b/pkg/gui/editors.go index 53ec9c6b2..f99f72176 100644 --- a/pkg/gui/editors.go +++ b/pkg/gui/editors.go @@ -119,6 +119,13 @@ func (gui *Gui) onMenuFilterContentChanged(content string) { gui.helpers.Search.ApplyFilter(menuContext, content) } +func (gui *Gui) pasteIntoSearch(text string) { + v := gui.Views.Search + if typePastedTextIntoSingleLineView(v, text) { + gui.helpers.Search.OnPromptContentChanged(v.TextArea.GetContent()) + } +} + func (gui *Gui) searchEditor(v *gocui.View, key gocui.Key) bool { matched := gui.handleEditorKeypress(v, key, false) v.RenderTextArea() diff --git a/pkg/gui/views.go b/pkg/gui/views.go index c7c648f94..340872769 100644 --- a/pkg/gui/views.go +++ b/pkg/gui/views.go @@ -101,6 +101,10 @@ func (gui *Gui) createAllViews() error { gui.Views.Search.Editable = true gui.Views.Search.Frame = false gui.Views.Search.Editor = gocui.EditorFunc(gui.searchEditor) + gui.Views.Search.OnPaste = func(text string) error { + gui.pasteIntoSearch(text) + return nil + } for _, view := range []*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.MergeConflicts} { view.Wrap = true diff --git a/pkg/integration/components/search_driver.go b/pkg/integration/components/search_driver.go index 96a706a65..77b4c878f 100644 --- a/pkg/integration/components/search_driver.go +++ b/pkg/integration/components/search_driver.go @@ -24,6 +24,13 @@ func (self *SearchDriver) Type(value string) *SearchDriver { return self } +// pastes the text the way a terminal does it +func (self *SearchDriver) Paste(text string) *SearchDriver { + self.t.paste(text) + + return self +} + func (self *SearchDriver) Clear() *SearchDriver { self.t.press(ClearKey) diff --git a/pkg/integration/tests/filter_and_search/paste_into_search_prompt.go b/pkg/integration/tests/filter_and_search/paste_into_search_prompt.go new file mode 100644 index 000000000..1560644c8 --- /dev/null +++ b/pkg/integration/tests/filter_and_search/paste_into_search_prompt.go @@ -0,0 +1,49 @@ +package filter_and_search + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var PasteIntoSearchPrompt = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Paste multi-line text into the search prompt", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.EmptyCommit("two") + shell.EmptyCommit("three") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("three").IsSelected(), + Contains("two"), + Contains("one"), + ). + Press(keys.Universal.StartSearch) + + t.ExpectSearch(). + Paste("\ntwo\n") + + t.Views().Search(). + IsFocused(). + Content(Equals("two")) + + t.ExpectSearch(). + Confirm() + + t.Views().Search(). + IsVisible(). + Content(Contains("matches for 'two' (1 of 1)")) + + t.Views().Commits(). + Lines( + Contains("three"), + Contains("two").IsSelected(), + Contains("one"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 7b8c23905..79d40de3e 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -339,6 +339,7 @@ var tests = []*components.IntegrationTest{ filter_and_search.NewSearch, filter_and_search.PasteIntoKeybindingsMenu, filter_and_search.PasteIntoMenuFilter, + filter_and_search.PasteIntoSearchPrompt, filter_and_search.RerenderTheSearchedMainView, filter_and_search.SearchALongDiff, filter_and_search.SearchStatusAfterARerender,