mirror of
https://github.com/zoriya/jjui.git
synced 2026-08-16 02:44:50 +00:00
fix: handle Bubble Tea paste messages (#601)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user