Skip to content

Commit 366bf7d

Browse files
committed
fix arrow key navigation on deployment
1 parent 588eed5 commit 366bf7d

1 file changed

Lines changed: 37 additions & 16 deletions

File tree

internal/tui/deploy.go

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,25 @@ func (m deployModel) updateAccountSelection(msg tea.Msg) (tea.Model, tea.Cmd) {
234234
m.accountFilter = ""
235235
m.status = ""
236236
return m, nil
237+
case "up", "k":
238+
filteredAccounts := m.getFilteredAccounts()
239+
if m.accountCursor > 0 {
240+
m.accountCursor--
241+
} else if len(filteredAccounts) > 0 {
242+
// Wrap around to the bottom
243+
m.accountCursor = len(filteredAccounts) - 1
244+
}
245+
return m, nil
246+
case "down", "j":
247+
filteredAccounts := m.getFilteredAccounts()
248+
if len(filteredAccounts) > 0 {
249+
if m.accountCursor < len(filteredAccounts)-1 {
250+
m.accountCursor++
251+
} else {
252+
m.accountCursor = 0 // Wrap around to the top
253+
}
254+
}
255+
return m, nil
237256
case "esc":
238257
if m.isFilteringAccount {
239258
m.isFilteringAccount = false
@@ -263,10 +282,11 @@ func (m deployModel) updateAccountSelection(msg tea.Msg) (tea.Model, tea.Cmd) {
263282
m.isFilteringAccount = false
264283
return m, nil
265284
}
266-
if len(m.accounts) == 0 {
285+
filteredAccounts := m.getFilteredAccounts()
286+
if len(filteredAccounts) == 0 {
267287
return m, nil
268288
}
269-
m.selectedAccount = m.accounts[m.accountCursor]
289+
m.selectedAccount = filteredAccounts[m.accountCursor]
270290

271291
switch m.action {
272292
case actionGetKeys:
@@ -288,10 +308,6 @@ func (m deployModel) updateAccountSelection(msg tea.Msg) (tea.Model, tea.Cmd) {
288308
m.accountFilter += msg.String()
289309
return m, nil
290310
}
291-
if m.accountFilter != "" && !m.isFilteringAccount {
292-
// Navigation keys etc. handled above
293-
return m, nil
294-
}
295311
}
296312
case startFilteringMsg:
297313
// no-op, just to trigger filter mode
@@ -300,6 +316,20 @@ func (m deployModel) updateAccountSelection(msg tea.Msg) (tea.Model, tea.Cmd) {
300316
return m, nil
301317
}
302318

319+
// getFilteredAccounts is a helper to get the list of accounts based on the current filter.
320+
func (m *deployModel) getFilteredAccounts() []model.Account {
321+
if m.accountFilter == "" {
322+
return m.accounts
323+
}
324+
var filteredAccounts []model.Account
325+
for _, acc := range m.accounts {
326+
if strings.Contains(strings.ToLower(acc.String()), strings.ToLower(m.accountFilter)) {
327+
filteredAccounts = append(filteredAccounts, acc)
328+
}
329+
}
330+
return filteredAccounts
331+
}
332+
303333
// updateSelectTag handles input when the user is selecting a tag.
304334
func (m deployModel) updateSelectTag(msg tea.Msg) (tea.Model, tea.Cmd) {
305335
switch msg := msg.(type) {
@@ -447,16 +477,7 @@ func (m deployModel) View() string {
447477
case deployStateSelectAccount:
448478
title := titleStyle.Render(i18n.T("deploy.select_account"))
449479
var listItems []string
450-
var filteredAccounts []model.Account
451-
if m.accountFilter != "" {
452-
for _, acc := range m.accounts {
453-
if strings.Contains(strings.ToLower(acc.String()), strings.ToLower(m.accountFilter)) {
454-
filteredAccounts = append(filteredAccounts, acc)
455-
}
456-
}
457-
} else {
458-
filteredAccounts = m.accounts
459-
}
480+
filteredAccounts := m.getFilteredAccounts()
460481
if m.accountCursor >= len(filteredAccounts) {
461482
m.accountCursor = 0
462483
}

0 commit comments

Comments
 (0)