Skip to content

Commit

Permalink
simpler matching
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 21, 2024
1 parent 5fdee1f commit de7ca7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/textual/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def _show_no_matches() -> None:
_show_no_matches,
)

async def _watch__list_visible(self) -> None:
def _watch__list_visible(self) -> None:
"""React to the list visible flag being toggled."""
self.query_one(CommandList).set_class(self._list_visible, "--visible")
self.query_one("#--input", Horizontal).set_class(
Expand Down
15 changes: 10 additions & 5 deletions src/textual/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ def highlight(self, candidate: str) -> Text:
if match is None:
return text
assert match.lastindex is not None
offsets = [
match.span(group_no)[0] for group_no in range(1, match.lastindex + 1)
]
for offset in offsets:
text.stylize(self._match_style, offset, offset + 1)
if self._query in text.plain:
# Favor complete matches
offset = text.plain.index(self._query)
text.stylize(self._match_style, offset, offset + len(self._query))
else:
offsets = [
match.span(group_no)[0] for group_no in range(1, match.lastindex + 1)
]
for offset in offsets:
text.stylize(self._match_style, offset, offset + 1)

return text

0 comments on commit de7ca7a

Please sign in to comment.