From 64e17a007c2c6f6e3c28e02336a39d9221f68cfd Mon Sep 17 00:00:00 2001 From: Lucas Becirspahic Date: Tue, 29 Sep 2026 14:53:18 +0200 Subject: [PATCH] Allow filtering on table instead of schema --- sqlit/shared/ui/widgets_autocomplete.py | 11 +++++++++-- tests/ui/test_autocomplete_dropdown.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sqlit/shared/ui/widgets_autocomplete.py b/sqlit/shared/ui/widgets_autocomplete.py index 24b344ea..b6f5ba71 100644 --- a/sqlit/shared/ui/widgets_autocomplete.py +++ b/sqlit/shared/ui/widgets_autocomplete.py @@ -74,12 +74,19 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.filter_text: str = "" def set_items(self, items: list[str], filter_text: str = "") -> None: - """Set the autocomplete items and filter.""" + """Set the autocomplete items and filter by any identifier component.""" self.items = items self.filter_text = filter_text.lower() if self.filter_text: - self.filtered_items = [item for item in items if item.lower().startswith(self.filter_text)] + self.filtered_items = [ + item + for item in items + if any( + part.lower().startswith(self.filter_text) + for part in item.split(".") + ) + ][:50] else: self.filtered_items = items[:50] # Show more items with scrolling diff --git a/tests/ui/test_autocomplete_dropdown.py b/tests/ui/test_autocomplete_dropdown.py index b712442b..d660a3bf 100644 --- a/tests/ui/test_autocomplete_dropdown.py +++ b/tests/ui/test_autocomplete_dropdown.py @@ -15,6 +15,25 @@ def compose(self) -> ComposeResult: yield AutocompleteDropdown() +class TestAutocompleteDropdownFiltering: + """Tests for preserving items selected by the completion engine.""" + + @pytest.mark.asyncio + async def test_filters_qualified_names_by_any_identifier_part(self) -> None: + """Qualified names match both their schema and table components.""" + app = _DropdownTestApp() + async with app.run_test() as pilot: + dropdown = app.query_one(AutocompleteDropdown) + + dropdown.set_items(["Visualsation.Latency"], "latency") + await pilot.pause() + assert dropdown.filtered_items == ["Visualsation.Latency"] + + dropdown.set_items(["Visualsation.Latency", "Visualsation.Other"], "Visualsation") + await pilot.pause() + assert dropdown.filtered_items == ["Visualsation.Latency", "Visualsation.Other"] + + class TestAutocompleteDropdownWidth: """Tests for dynamic width sizing based on filtered items."""