Don't highlight filtered items until search is blurred

This commit is contained in:
Christian Rocha 2020-11-10 18:48:34 -05:00 committed by Christian Rocha
parent ef0f5338f4
commit 2e1579542e
2 changed files with 10 additions and 17 deletions

View file

@ -701,11 +701,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
m.state = stashStateReady
}
case "ctrl+k", "up":
m.moveCursorUp()
m.state = stashStateShowFiltered
case "ctrl+j", "down":
m.moveCursorDown()
case "ctrl+k", "ctrl+j", "up", "down":
m.state = stashStateShowFiltered
}
}

View file

@ -78,7 +78,15 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
title = truncate(title, truncateTo)
}
if index == m.index {
isSelected := index == m.index
notSearchingNotes := m.state != stashStateSearchNotes
// If there are multiple items being filtered we don't highlight a selected
// item in the results. If we've filtered down to one item, however,
// highlight that first item since pressing return will open it.
singleFilteredItem := m.state == stashStateSearchNotes && len(m.getNotes()) == 1
if isSelected && notSearchingNotes || singleFilteredItem {
// Selected item
switch m.state {
@ -92,17 +100,6 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
icon = ""
title = textinput.View(m.noteInput)
date = dullYellowFg(date)
case stashStateSearchNotes:
if len(m.getNotes()) != 1 && m.searchInput.Value() == "" {
gutter = dimDullFuchsiaFg(verticalLine)
icon = dimDullFuchsiaFg(icon)
title = dimFuchsiaFg(title)
date = dimDullFuchsiaFg(date)
break
}
// If we've filtered down to exactly item color it as though it's
// not filtered, since pressing return will open it.
fallthrough
default:
gutter = dullFuchsiaFg(verticalLine)
icon = dullFuchsiaFg(icon)