mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-12 15:53:33 -04:00
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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e68f195e33
commit
417dea6381
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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"))
|
||||
},
|
||||
})
|
||||
@@ -580,6 +580,7 @@ var tests = []*components.IntegrationTest{
|
||||
misc.DirenvUnloadsOnBlockedEnvrc,
|
||||
misc.FilterRecentRepos,
|
||||
misc.InitialOpen,
|
||||
misc.PasteIntoPrompt,
|
||||
misc.RecentReposBranchColumn,
|
||||
misc.RecentReposColumnWidths,
|
||||
misc.RecentReposOnLaunch,
|
||||
|
||||
Reference in New Issue
Block a user