Skip to content

Commit 157e843

Browse files
fix: handle paste in prview and issueview inputboxes
Bug: Pasting text into the comment, approve, assign, or label inputbox does nothing. Cause: Bubbletea v2 enables bracketed paste by default, delivering pasted text as tea.PasteMsg rather than individual tea.KeyMsg events. The Update() methods in prview and issueview only had a case for tea.KeyMsg, so PasteMsg was silently dropped. Fix: Add a tea.PasteMsg case in both the prview and issueview Update() methods that forwards the message to the inputbox when it’s focused. Fixes #811
1 parent 129bf09 commit 157e843

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

internal/tui/components/issueview/action_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,37 @@ func TestInputBoxTextNotReplacedByStaleAutocomplete(t *testing.T) {
263263
require.Equal(t, "This is my comment about fea", m.inputBox.Value(),
264264
"input text should not be modified by Tab when autocomplete is reset")
265265
}
266+
267+
func TestPasteInCommentMode(t *testing.T) {
268+
m := newTestModelForAction(t)
269+
m.isCommenting = true
270+
m.inputBox.Focus()
271+
272+
msg := tea.PasteMsg{Content: "pasted text"}
273+
m, _, _ = m.Update(msg)
274+
275+
require.Contains(t, m.inputBox.Value(), "pasted text",
276+
"pasted text should appear in the inputbox")
277+
}
278+
279+
func TestPasteInLabelMode(t *testing.T) {
280+
m := newTestModelForAction(t)
281+
m.isLabeling = true
282+
m.inputBox.Focus()
283+
284+
msg := tea.PasteMsg{Content: "bug, feature"}
285+
m, _, _ = m.Update(msg)
286+
287+
require.Contains(t, m.inputBox.Value(), "bug, feature",
288+
"pasted text should appear in the inputbox during labeling")
289+
}
290+
291+
func TestPasteIgnoredWhenNotInputting(t *testing.T) {
292+
m := newTestModelForAction(t)
293+
294+
msg := tea.PasteMsg{Content: "should not appear"}
295+
m, _, _ = m.Update(msg)
296+
297+
require.Empty(t, m.inputBox.Value(),
298+
"paste should be ignored when no input mode is active")
299+
}

internal/tui/components/issueview/issueview.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd, *IssueAction) {
9090
)
9191

9292
switch msg := msg.(type) {
93+
case tea.PasteMsg:
94+
if m.IsTextInputBoxFocused() {
95+
m.inputBox, taCmd = m.inputBox.Update(msg)
96+
cmds = append(cmds, taCmd)
97+
}
98+
9399
case RepoLabelsFetchedMsg:
94100
clearCmd := m.ac.SetFetchSuccess()
95101
m.repoLabels = msg.Labels

internal/tui/components/prview/action_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,37 @@ func TestMsgToActionWithReboundKeys(t *testing.T) {
209209
require.NotNil(t, action, "expected action for rebound key")
210210
require.Equal(t, PRActionApprove, action.Type, "expected approve action for rebound key")
211211
}
212+
213+
func TestPasteInCommentMode(t *testing.T) {
214+
m := newTestModelForAction(t)
215+
m.isCommenting = true
216+
m.inputBox.Focus()
217+
218+
msg := tea.PasteMsg{Content: "pasted text"}
219+
m, _ = m.Update(msg)
220+
221+
require.Contains(t, m.inputBox.Value(), "pasted text",
222+
"pasted text should appear in the inputbox")
223+
}
224+
225+
func TestPasteInApproveMode(t *testing.T) {
226+
m := newTestModelForAction(t)
227+
m.isApproving = true
228+
m.inputBox.Focus()
229+
230+
msg := tea.PasteMsg{Content: "approval comment"}
231+
m, _ = m.Update(msg)
232+
233+
require.Contains(t, m.inputBox.Value(), "approval comment",
234+
"pasted text should appear in the inputbox during approval")
235+
}
236+
237+
func TestPasteIgnoredWhenNotInputting(t *testing.T) {
238+
m := newTestModelForAction(t)
239+
240+
msg := tea.PasteMsg{Content: "should not appear"}
241+
m, _ = m.Update(msg)
242+
243+
require.Empty(t, m.inputBox.Value(),
244+
"paste should be ignored when no input mode is active")
245+
}

internal/tui/components/prview/prview.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
8080
)
8181

8282
switch msg := msg.(type) {
83+
case tea.PasteMsg:
84+
if m.IsTextInputBoxFocused() {
85+
m.inputBox, taCmd = m.inputBox.Update(msg)
86+
cmds = append(cmds, taCmd)
87+
}
88+
8389
case tea.KeyMsg:
8490
if m.isCommenting {
8591
switch msg.String() {

0 commit comments

Comments
 (0)