From a6c4d6cdf14c655905ff8ad7c7efbb56288199d1 Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Sun, 30 Nov 2025 18:14:25 +0100 Subject: [PATCH] replace space characters with minus charcater when writing new branch names --- pkg/gui/controllers/branches_controller.go | 5 +++-- pkg/gui/controllers/helpers/refs_helper.go | 10 ++++++---- pkg/gui/editors.go | 9 +++++++++ pkg/gui/popup/popup_handler.go | 23 +++++++++++----------- pkg/gui/types/common.go | 18 +++++++++-------- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index f430f7b0ef8..49cf814add3 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -703,8 +703,9 @@ func (self *BranchesController) createResetMenu(selectedBranch *models.Branch) e func (self *BranchesController) rename(branch *models.Branch) error { promptForNewName := func() error { self.c.Prompt(types.PromptOpts{ - Title: self.c.Tr.NewBranchNamePrompt + " " + branch.Name + ":", - InitialContent: branch.Name, + Title: self.c.Tr.NewBranchNamePrompt + " " + branch.Name + ":", + InitialContent: branch.Name, + ReplaceSpacesWithDashes: true, HandleConfirm: func(newBranchName string) error { self.c.LogAction(self.c.Tr.Actions.RenameBranch) if err := self.c.Git().Branch.Rename(branch.Name, helpers.SanitizedBranchName(newBranchName)); err != nil { diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 1976bf3867d..21086756088 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -355,8 +355,9 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest } self.c.Prompt(types.PromptOpts{ - Title: message, - InitialContent: suggestedBranchName, + Title: message, + InitialContent: suggestedBranchName, + ReplaceSpacesWithDashes: true, HandleConfirm: func(response string) error { self.c.LogAction(self.c.Tr.Actions.CreateBranch) newBranchName := SanitizedBranchName(response) @@ -418,8 +419,9 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error { } self.c.Prompt(types.PromptOpts{ - Title: prompt, - InitialContent: suggestedBranchName, + Title: prompt, + InitialContent: suggestedBranchName, + ReplaceSpacesWithDashes: true, HandleConfirm: func(response string) error { self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch) newBranchName := SanitizedBranchName(response) diff --git a/pkg/gui/editors.go b/pkg/gui/editors.go index 6345c93cf15..ab8d873ba91 100644 --- a/pkg/gui/editors.go +++ b/pkg/gui/editors.go @@ -73,6 +73,15 @@ func (gui *Gui) commitDescriptionEditor(v *gocui.View, key gocui.Key, ch rune, m } func (gui *Gui) promptEditor(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) bool { + // Replace spaces with dashes if the option is enabled + if key == gocui.KeySpace { + if opts := gui.State.GetCurrentPopupOpts(); opts != nil && opts.ReplaceSpacesWithDashes { + v.TextArea.TypeRune('-') + v.RenderTextArea() + return true + } + } + matched := gui.handleEditorKeypress(v.TextArea, key, ch, mod, false) v.RenderTextArea() diff --git a/pkg/gui/popup/popup_handler.go b/pkg/gui/popup/popup_handler.go index d8824016f48..78d0a8bd2c5 100644 --- a/pkg/gui/popup/popup_handler.go +++ b/pkg/gui/popup/popup_handler.go @@ -131,17 +131,18 @@ func (self *PopupHandler) ConfirmIf(condition bool, opts types.ConfirmOpts) erro func (self *PopupHandler) Prompt(opts types.PromptOpts) { self.createPopupPanelFn(context.Background(), types.CreatePopupPanelOpts{ - Title: opts.Title, - Prompt: opts.InitialContent, - Editable: true, - HandleConfirmPrompt: opts.HandleConfirm, - HandleClose: opts.HandleClose, - HandleDeleteSuggestion: opts.HandleDeleteSuggestion, - FindSuggestionsFunc: opts.FindSuggestionsFunc, - AllowEditSuggestion: opts.AllowEditSuggestion, - AllowEmptyInput: opts.AllowEmptyInput, - PreserveWhitespace: opts.PreserveWhitespace, - Mask: opts.Mask, + Title: opts.Title, + Prompt: opts.InitialContent, + Editable: true, + HandleConfirmPrompt: opts.HandleConfirm, + HandleClose: opts.HandleClose, + HandleDeleteSuggestion: opts.HandleDeleteSuggestion, + FindSuggestionsFunc: opts.FindSuggestionsFunc, + AllowEditSuggestion: opts.AllowEditSuggestion, + AllowEmptyInput: opts.AllowEmptyInput, + PreserveWhitespace: opts.PreserveWhitespace, + Mask: opts.Mask, + ReplaceSpacesWithDashes: opts.ReplaceSpacesWithDashes, }) } diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index 2afe4f7d3b8..4163f55c2ff 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -169,11 +169,12 @@ type CreatePopupPanelOpts struct { HandleClose func() error HandleDeleteSuggestion func(int) error - FindSuggestionsFunc func(string) []*Suggestion - Mask bool - AllowEditSuggestion bool - AllowEmptyInput bool - PreserveWhitespace bool + FindSuggestionsFunc func(string) []*Suggestion + Mask bool + AllowEditSuggestion bool + AllowEmptyInput bool + PreserveWhitespace bool + ReplaceSpacesWithDashes bool } type ConfirmOpts struct { @@ -195,9 +196,10 @@ type PromptOpts struct { AllowEmptyInput bool PreserveWhitespace bool // CAPTURE THIS - HandleClose func() error - HandleDeleteSuggestion func(int) error - Mask bool + HandleClose func() error + HandleDeleteSuggestion func(int) error + Mask bool + ReplaceSpacesWithDashes bool } type MenuSection struct {