Подсветка фильтра не пропадает на строке под курсором
This commit is contained in:
@@ -149,7 +149,11 @@ def clip(text: str, room: int) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def highlighted_content(text: str, query: str) -> Content:
|
def highlighted_content(text: str, query: str) -> Content:
|
||||||
"""Подсветить куски, из-за которых строка прошла фильтр: иначе непонятно, почему она тут."""
|
"""Подсветить куски, из-за которых строка прошла фильтр: иначе непонятно, почему она тут.
|
||||||
|
|
||||||
|
Стиль только начертанием, без цвета: фон строки под курсором — тот же $primary,
|
||||||
|
и цветная подсветка на нём сливалась с фоном, съедая совпавшие буквы.
|
||||||
|
"""
|
||||||
content = Content(text)
|
content = Content(text)
|
||||||
if not query:
|
if not query:
|
||||||
return content
|
return content
|
||||||
@@ -157,7 +161,7 @@ def highlighted_content(text: str, query: str) -> Content:
|
|||||||
for word in query.lower().split():
|
for word in query.lower().split():
|
||||||
start = low.find(word)
|
start = low.find(word)
|
||||||
if start >= 0:
|
if start >= 0:
|
||||||
content = content.stylize("bold $primary", start, start + len(word))
|
content = content.stylize("bold underline", start, start + len(word))
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,6 +75,14 @@ def test_matches_common_filter():
|
|||||||
assert core.matches("что угодно", "")
|
assert core.matches("что угодно", "")
|
||||||
|
|
||||||
|
|
||||||
|
def test_filter_highlight_has_no_color():
|
||||||
|
"""Фон строки под курсором — $primary: цветная подсветка совпадения слилась бы с ним."""
|
||||||
|
content = tui.highlighted_content("zpas_core", "core")
|
||||||
|
styles = " ".join(str(span.style) for span in content.spans)
|
||||||
|
assert styles, "совпадение обязано быть выделено"
|
||||||
|
assert "$" not in styles and "color" not in styles
|
||||||
|
|
||||||
|
|
||||||
def test_pick_uses_matches(monkeypatch):
|
def test_pick_uses_matches(monkeypatch):
|
||||||
"""Текстовый режим и TUI обязаны фильтровать одинаково — через одну функцию."""
|
"""Текстовый режим и TUI обязаны фильтровать одинаково — через одну функцию."""
|
||||||
answers = iter(["zp core", "1"])
|
answers = iter(["zp core", "1"])
|
||||||
|
|||||||
Reference in New Issue
Block a user