Skip to content

Commit 61dfc6b

Browse files
fix: handle paste in inputboxes (#813)
**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 `PasteMsg` rather than individual `KeyMsg` events. The inputbox controller only handled `KeyMsg`, so `PasteMsg` was silently dropped. **Fix:** Add a `PasteMsg` case in `Controller.Update()` that forwards the message to the underlying textarea when the controller is active. Fixes #811
1 parent f0b67d7 commit 61dfc6b

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

internal/tui/components/detailedit/controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ func (c Controller) Update(msg tea.Msg) (Controller, tea.Cmd, *Submit, bool) {
201201
)
202202

203203
switch msg := msg.(type) {
204+
case tea.PasteMsg:
205+
if c.Active() {
206+
c.inputBox, taCmd = c.inputBox.Update(msg)
207+
cmds = append(cmds, taCmd)
208+
return c, tea.Batch(cmds...), nil, true
209+
}
210+
return c, nil, nil, false
211+
204212
case RepoLabelsFetchedMsg:
205213
c.repoLabels = msg.Labels
206214
c.ac.SetSuggestions(labelSuggestions(msg.Labels))

internal/tui/components/detailedit/controller_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,56 @@ func TestUnassignModeDoesNotUseAutocomplete(t *testing.T) {
338338

339339
require.False(t, c.usesAutocomplete())
340340
}
341+
342+
func TestPasteInCommentMode(t *testing.T) {
343+
data.ClearUserCache()
344+
c := newTestController(t)
345+
c, _ = c.Enter(EnterOptions{
346+
Mode: ModeComment,
347+
Prompt: "comment",
348+
Source: dataautocomplete.UserMentionSource{},
349+
Repo: testRepo(),
350+
SuggestionKind: SuggestionUsers,
351+
EnterFetch: FetchNone,
352+
ConfirmDiscardOnCancel: true,
353+
HideAutocompleteWhenContextEmpty: true,
354+
})
355+
356+
msg := tea.PasteMsg{Content: "pasted text"}
357+
c, _, _, handled := c.Update(msg)
358+
359+
require.True(t, handled)
360+
require.Contains(t, c.inputBox.Value(), "pasted text",
361+
"pasted text should appear in the inputbox")
362+
}
363+
364+
func TestPasteInAssignMode(t *testing.T) {
365+
data.ClearUserCache()
366+
c := newTestController(t)
367+
c, _ = c.Enter(EnterOptions{
368+
Mode: ModeAssign,
369+
Prompt: "assign",
370+
Source: dataautocomplete.WhitespaceSource{},
371+
Repo: testRepo(),
372+
SuggestionKind: SuggestionUsers,
373+
EnterFetch: FetchNone,
374+
HideAutocompleteWhenContextEmpty: false,
375+
})
376+
377+
msg := tea.PasteMsg{Content: "alice bob"}
378+
c, _, _, handled := c.Update(msg)
379+
380+
require.True(t, handled)
381+
require.Contains(t, c.inputBox.Value(), "alice bob",
382+
"pasted text should appear in the inputbox during assignment")
383+
}
384+
385+
func TestPasteIgnoredWhenInactive(t *testing.T) {
386+
c := newTestController(t)
387+
388+
msg := tea.PasteMsg{Content: "should not appear"}
389+
_, _, _, handled := c.Update(msg)
390+
391+
require.False(t, handled,
392+
"paste should not be handled when controller is inactive")
393+
}

0 commit comments

Comments
 (0)