Add search autocomplete and fix search state restoration

- Add SuggestFromList with Himalaya keywords for search input autocomplete
- Cache and restore metadata_by_id when cancelling search (fixes navigation)
- Set search_mode=True when opening panel for consistent Escape behavior
- Fix SearchPanel CSS vertical alignment with explicit heights
This commit is contained in:
Bendt
2025-12-19 15:33:42 -05:00
parent 5deebbbf98
commit 9a2f8ee211
2 changed files with 38 additions and 3 deletions

View File

@@ -17,6 +17,32 @@ from textual.screen import ModalScreen
from textual.timer import Timer
from textual.widget import Widget
from textual.widgets import Button, Input, Label, Static
from textual.suggester import SuggestFromList
# Himalaya search keywords for autocomplete
HIMALAYA_KEYWORDS = [
"from ",
"to ",
"subject ",
"body ",
"date ",
"before ",
"after ",
"flag ",
"not ",
"and ",
"or ",
"order by ",
"order by date ",
"order by date asc",
"order by date desc",
"order by from ",
"order by to ",
"order by subject ",
"flag seen",
"flag flagged",
"not flag seen",
]
HIMALAYA_SEARCH_HELP = """
## Himalaya Search Query Syntax
@@ -125,7 +151,7 @@ class SearchPanel(Widget):
}
SearchPanel > Horizontal {
height: auto;
height: 3;
width: 100%;
align: left middle;
}
@@ -134,6 +160,7 @@ class SearchPanel(Widget):
width: auto;
padding: 0 1;
color: $primary;
height: 1;
}
SearchPanel Input {
@@ -151,6 +178,7 @@ class SearchPanel(Widget):
width: auto;
padding: 0 1;
color: $text-muted;
height: 1;
}
"""
@@ -197,6 +225,7 @@ class SearchPanel(Widget):
yield Input(
placeholder="from <name> or subject <text> or body <text>...",
id="search-input",
suggester=SuggestFromList(HIMALAYA_KEYWORDS, case_sensitive=False),
)
yield Label("", classes="search-status", id="search-status")
yield Button("?", variant="default", id="help-btn")