Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/prompt_toolkit/completion/fuzzy_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def sort_key(fuzzy_match: _FuzzyMatch) -> tuple[int, int]:
display_meta=match.completion._display_meta,
display=self._get_display(match, word_before_cursor),
style=match.completion.style,
selected_style=match.completion.selected_style,
)

def _get_display(
Expand Down
18 changes: 18 additions & 0 deletions tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
import tempfile
from contextlib import contextmanager

import pytest

from prompt_toolkit.completion import (
CompleteEvent,
Completer,
Completion,
FuzzyCompleter,
FuzzyWordCompleter,
NestedCompleter,
PathCompleter,
Expand Down Expand Up @@ -400,6 +405,19 @@ def test_fuzzy_completer():
assert [c.text for c in completions] == ["users.txt", "accounts.txt"]


@pytest.mark.parametrize("text", ["", "rd"])
def test_fuzzy_completer_preserves_styles(text):
class StyledCompleter(Completer):
def get_completions(self, document, complete_event):
yield Completion("red", style="fg:red", selected_style="fg:white bg:red")

completer = FuzzyCompleter(StyledCompleter())
completions = list(completer.get_completions(Document(text), CompleteEvent()))
assert len(completions) == 1
assert completions[0].style == "fg:red"
assert completions[0].selected_style == "fg:white bg:red"


def test_nested_completer():
completer = NestedCompleter.from_nested_dict(
{
Expand Down
Loading