Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/gui/controllers/branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions pkg/gui/controllers/helpers/refs_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/gui/editors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 12 additions & 11 deletions pkg/gui/popup/popup_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
18 changes: 10 additions & 8 deletions pkg/gui/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down