@@ -18,8 +18,10 @@ import (
18
18
)
19
19
20
20
var (
21
- htmlCommentRegex = regexp .MustCompile ("(?U)<!--(.|[[:space:]])*-->" )
22
- lineCleanupRegex = regexp .MustCompile (`((\n)+|^)([^\r\n]*\|[^\r\n]*(\n)?)+` )
21
+ htmlCommentRegex = regexp .MustCompile ("(?U)<!--(.|[[:space:]])*-->" )
22
+ lineCleanupRegex = regexp .MustCompile (`((\n)+|^)([^\r\n]*\|[^\r\n]*(\n)?)+` )
23
+ commentPrompt = "Leave a comment..."
24
+ approvalPrompt = "Approve with comment..."
23
25
)
24
26
25
27
type Model struct {
@@ -28,10 +30,11 @@ type Model struct {
28
30
pr * pr.PullRequest
29
31
width int
30
32
31
- isCommenting bool
32
- isApproving bool
33
- isAssigning bool
34
- isUnassigning bool
33
+ ShowConfirmCancel bool
34
+ isCommenting bool
35
+ isApproving bool
36
+ isAssigning bool
37
+ isUnassigning bool
35
38
36
39
inputBox inputbox.Model
37
40
}
@@ -73,9 +76,22 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
73
76
return m , cmd
74
77
75
78
case tea .KeyEsc , tea .KeyCtrlC :
76
- m .inputBox .Blur ()
77
- m .isCommenting = false
78
- return m , nil
79
+ if ! m .ShowConfirmCancel {
80
+ m .shouldCancelComment ()
81
+ }
82
+ default :
83
+ if msg .String () == "Y" || msg .String () == "y" {
84
+ if m .shouldCancelComment () {
85
+ return m , nil
86
+ }
87
+ }
88
+ if m .ShowConfirmCancel && (msg .String () == "N" || msg .String () == "n" ) {
89
+ m .inputBox .SetPrompt (commentPrompt )
90
+ m .ShowConfirmCancel = false
91
+ return m , nil
92
+ }
93
+ m .inputBox .SetPrompt (commentPrompt )
94
+ m .ShowConfirmCancel = false
79
95
}
80
96
81
97
m .inputBox , taCmd = m .inputBox .Update (msg )
@@ -94,9 +110,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
94
110
return m , cmd
95
111
96
112
case tea .KeyEsc , tea .KeyCtrlC :
97
- m .inputBox .Blur ()
98
- m .isApproving = false
99
- return m , nil
113
+ if m .shouldCancelComment () {
114
+ return m , nil
115
+ }
116
+ default :
117
+ m .inputBox .SetPrompt (approvalPrompt )
118
+ m .ShowConfirmCancel = false
100
119
}
101
120
102
121
m .inputBox , taCmd = m .inputBox .Update (msg )
@@ -345,12 +364,25 @@ func (m *Model) UpdateProgramContext(ctx *context.ProgramContext) {
345
364
m .inputBox .UpdateProgramContext (ctx )
346
365
}
347
366
367
+ func (m * Model ) shouldCancelComment () bool {
368
+ if ! m .ShowConfirmCancel {
369
+ m .inputBox .SetPrompt (lipgloss .NewStyle ().Foreground (m .ctx .Theme .ErrorText ).Render ("Discard comment? (y/N)" ))
370
+ m .ShowConfirmCancel = true
371
+ return false
372
+ }
373
+ m .inputBox .Blur ()
374
+ m .isCommenting = false
375
+ m .isApproving = false
376
+ m .ShowConfirmCancel = false
377
+ return true
378
+ }
379
+
348
380
func (m * Model ) SetIsCommenting (isCommenting bool ) tea.Cmd {
349
381
if ! m .isCommenting && isCommenting {
350
382
m .inputBox .Reset ()
351
383
}
352
384
m .isCommenting = isCommenting
353
- m .inputBox .SetPrompt ("Leave a comment..." )
385
+ m .inputBox .SetPrompt (commentPrompt )
354
386
355
387
if isCommenting {
356
388
return tea .Sequence (textarea .Blink , m .inputBox .Focus ())
@@ -371,7 +403,7 @@ func (m *Model) SetIsApproving(isApproving bool) tea.Cmd {
371
403
m .inputBox .Reset ()
372
404
}
373
405
m .isApproving = isApproving
374
- m .inputBox .SetPrompt ("Approve with comment..." )
406
+ m .inputBox .SetPrompt (approvalPrompt )
375
407
m .inputBox .SetValue ("LGTM" )
376
408
377
409
if isApproving {
0 commit comments