@@ -115,6 +115,7 @@ func CreateCommitMsg() {
115115
116116 currentMessage := strings .TrimSpace (commitMsg )
117117 currentStyleLabel := stylePresets [0 ].Label
118+ var currentStyleOpts * types.GenerationOptions
118119 accepted := false
119120 finalMessage := ""
120121
@@ -144,7 +145,7 @@ interactionLoop:
144145 accepted = true
145146 break interactionLoop
146147 case actionRegenerateOption :
147- opts , styleLabel , err := promptStyleSelection (currentStyleLabel )
148+ opts , styleLabel , err := promptStyleSelection (currentStyleLabel , currentStyleOpts )
148149 if errors .Is (err , errSelectionCancelled ) {
149150 continue
150151 }
@@ -155,8 +156,9 @@ interactionLoop:
155156 if styleLabel != "" {
156157 currentStyleLabel = styleLabel
157158 }
159+ currentStyleOpts = opts
158160 nextAttempt := attempt + 1
159- generationOpts := withAttempt (opts , nextAttempt )
161+ generationOpts := withAttempt (currentStyleOpts , nextAttempt )
160162 spinner , err := pterm .DefaultSpinner .
161163 WithSequence ("⠋" , "⠙" , "⠹" , "⠸" , "⠼" , "⠴" , "⠦" , "⠧" , "⠇" , "⠏" ).
162164 Start (fmt .Sprintf ("Regenerating commit message (%s)..." , currentStyleLabel ))
@@ -260,10 +262,17 @@ func promptActionSelection() (string, error) {
260262 Show ()
261263}
262264
263- func promptStyleSelection (currentLabel string ) (* types.GenerationOptions , string , error ) {
264- options := make ([]string , 0 , len (stylePresets )+ 2 )
265+ func promptStyleSelection (currentLabel string , currentOpts * types.GenerationOptions ) (* types.GenerationOptions , string , error ) {
266+ options := make ([]string , 0 , len (stylePresets )+ 3 )
267+ foundCurrent := false
265268 for _ , preset := range stylePresets {
266269 options = append (options , preset .Label )
270+ if preset .Label == currentLabel {
271+ foundCurrent = true
272+ }
273+ }
274+ if currentOpts != nil && currentLabel != "" && ! foundCurrent {
275+ options = append (options , currentLabel )
267276 }
268277 options = append (options , customStyleOption , styleBackOption )
269278
@@ -274,22 +283,22 @@ func promptStyleSelection(currentLabel string) (*types.GenerationOptions, string
274283
275284 choice , err := selector .Show ()
276285 if err != nil {
277- return nil , currentLabel , err
286+ return currentOpts , currentLabel , err
278287 }
279288
280289 switch choice {
281290 case styleBackOption :
282- return nil , currentLabel , errSelectionCancelled
291+ return currentOpts , currentLabel , errSelectionCancelled
283292 case customStyleOption :
284293 text , err := pterm .DefaultInteractiveTextInput .
285294 WithDefaultText ("Describe the tone or style you're looking for" ).
286295 Show ()
287296 if err != nil {
288- return nil , currentLabel , err
297+ return currentOpts , currentLabel , err
289298 }
290299 text = strings .TrimSpace (text )
291300 if text == "" {
292- return nil , currentLabel , errSelectionCancelled
301+ return currentOpts , currentLabel , errSelectionCancelled
293302 }
294303 return & types.GenerationOptions {StyleInstruction : text }, formatCustomStyleLabel (text ), nil
295304 default :
@@ -301,8 +310,16 @@ func promptStyleSelection(currentLabel string) (*types.GenerationOptions, string
301310 return & types.GenerationOptions {StyleInstruction : preset .Instruction }, preset .Label , nil
302311 }
303312 }
313+ if currentOpts != nil && choice == currentLabel {
314+ clone := * currentOpts
315+ return & clone , currentLabel , nil
316+ }
304317 }
305318
319+ if currentOpts != nil && currentLabel != "" {
320+ clone := * currentOpts
321+ return & clone , currentLabel , nil
322+ }
306323 return nil , currentLabel , nil
307324}
308325
0 commit comments