Skip to content

Commit

Permalink
refactor: handle searching better
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Jun 3, 2024
1 parent 7cec053 commit 0629a17
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ var keys = keyMap{
}

func (m Model) handleKeys(msg tea.KeyMsg) (Model, tea.Cmd) {
if m.context == "search" {
switch msg.String() {
case "enter":
m = m.loadSearchValues()

case "ctrl+c":
case "esc":
case "/":
m = m.loadContent(m.table.Cursor())
m.table.Focus()
m.filter.Blur()
}

return m, nil
}

switch {
case key.Matches(msg, m.keys.Help):
m.help.ShowAll = !m.help.ShowAll
Expand Down Expand Up @@ -147,10 +163,6 @@ func (m Model) handleKeys(msg tea.KeyMsg) (Model, tea.Cmd) {
case "content":
m = m.loadHome()
m.table.SetCursor(m.feed.ID)
case "search":
m = m.loadContent(m.table.Cursor())
m.table.Focus()
m.filter.Blur()
}

case key.Matches(msg, m.keys.Open):
Expand All @@ -164,12 +176,6 @@ func (m Model) handleKeys(msg tea.KeyMsg) (Model, tea.Cmd) {
case "content":
m = m.loadReader()

case "search":
// NOTE: do not load search values if input is "o"
if msg.String() != "o" {
m = m.loadSearchValues()
}

default:
m = m.loadContent(m.table.Cursor())
m.table.SetCursor(0)
Expand Down

0 comments on commit 0629a17

Please sign in to comment.