fix: handle Bubble Tea paste messages (#601)

This commit is contained in:
Shardul Baral
2026-03-17 10:02:53 +00:00
committed by GitHub
parent 05e95d80bb
commit 2d1d51af2a
9 changed files with 38 additions and 12 deletions
+6 -2
View File
@@ -329,7 +329,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
return nil
case intents.Intent:
return m.handleIntent(msg)
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
if m.filterState == filterEditing {
updated, cmd := m.filterInput.Update(msg)
filterChanged := m.filterInput.Value() != updated.Value()
@@ -339,7 +339,11 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
return cmd
}
if cmd := m.handleIntent(intents.BookmarksApplyShortcut{Key: msg.String()}); cmd != nil {
keyMsg, ok := msg.(tea.KeyMsg)
if !ok {
return nil
}
if cmd := m.handleIntent(intents.BookmarksApplyShortcut{Key: keyMsg.String()}); cmd != nil {
return cmd
}
case updateItemsMsg:
+14
View File
@@ -97,3 +97,17 @@ main;.;false;false;false;86
test.SimulateModel(op, func() tea.Msg { return intents.BookmarksFilter{Kind: intents.BookmarksFilterMove} })
test.SimulateModel(op, func() tea.Msg { return intents.BookmarksFilter{Kind: intents.BookmarksFilterMove} })
}
func Test_FilterEditing_AcceptsPasteMsg(t *testing.T) {
commandRunner := test.NewTestCommandRunner(t)
commandRunner.Expect(jj.GitRemoteList()).SetOutput([]byte(""))
defer commandRunner.Verify()
commit := &jj.Commit{ChangeId: "abc123", CommitId: "commit123"}
op := NewModel(test.NewTestContext(commandRunner), commit, []string{"commit123"})
test.SimulateModel(op, func() tea.Msg { return intents.BookmarksOpenFilter{} })
test.SimulateModel(op, func() tea.Msg { return tea.PasteMsg{Content: "track feature"} })
assert.Equal(t, "track feature", op.filterInput.Value())
}
+7 -3
View File
@@ -127,14 +127,18 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
return newCmd(CancelledMsg{})
}
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
if m.filtering {
m.input, cmd = m.input.Update(msg)
m.filterOptions()
return cmd
}
keyMsg, ok := msg.(tea.KeyMsg)
if !ok {
return nil
}
if m.ordered {
if r := msg.String(); len(r) == 1 && r[0] >= '1' && r[0] <= '9' {
if r := keyMsg.String(); len(r) == 1 && r[0] >= '1' && r[0] <= '9' {
idx := int(r[0] - '1')
if idx < len(m.filteredOptions) {
m.selected = idx
@@ -142,7 +146,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
}
}
if m.filterable && msg.String() == "/" {
if m.filterable && keyMsg.String() == "/" {
m.filtering = true
m.input.Focus()
return textinput.Blink
+6 -2
View File
@@ -176,7 +176,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
return nil
case intents.Intent:
return m.handleIntent(msg)
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
if m.filterState == filterEditing {
updated, cmd := m.filterInput.Update(msg)
filterChanged := m.filterInput.Value() != updated.Value()
@@ -186,7 +186,11 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
return cmd
}
if cmd := m.handleIntent(intents.GitApplyShortcut{Key: msg.String()}); cmd != nil {
keyMsg, ok := msg.(tea.KeyMsg)
if !ok {
return nil
}
if cmd := m.handleIntent(intents.GitApplyShortcut{Key: keyMsg.String()}); cmd != nil {
return cmd
}
}
+1 -1
View File
@@ -173,7 +173,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
} else {
m.scroll = max(0, m.scroll+msg.Delta)
}
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
if m.filtering {
prev := m.input.Value()
var cmd tea.Cmd
+1 -1
View File
@@ -87,7 +87,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
return newCmd(CancelledMsg{})
}
return nil
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
var cmd tea.Cmd
m.input, cmd = m.input.Update(msg)
return cmd
@@ -161,7 +161,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
return nil
}
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
var cmd tea.Cmd
m.input, cmd = m.input.Update(msg)
m.search(m.input.Value())
+1 -1
View File
@@ -63,7 +63,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
}
}
return nil
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
var cmd tea.Cmd
m.textInput, cmd = m.textInput.Update(msg)
return cmd
+1 -1
View File
@@ -136,7 +136,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
return m.fuzzy.Update(msg)
}
return nil
case tea.KeyMsg:
case tea.KeyMsg, tea.PasteMsg:
if m.IsFocused() {
var cmd tea.Cmd
previous := m.input.Value()