From 6cc11ea541895eec901f0a811629e4acf07e179e Mon Sep 17 00:00:00 2001 From: Gerardo Lecaros Date: Tue, 2 May 2023 13:25:15 -0700 Subject: [PATCH 1/3] Adding pattern to NestedCompleter. --- src/prompt_toolkit/completion/nested.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/prompt_toolkit/completion/nested.py b/src/prompt_toolkit/completion/nested.py index a1d211ab0..16d4593c5 100644 --- a/src/prompt_toolkit/completion/nested.py +++ b/src/prompt_toolkit/completion/nested.py @@ -3,7 +3,7 @@ """ from __future__ import annotations -from typing import Any, Iterable, Mapping, Set, Union +from typing import Any, Iterable, Mapping, Set, Union, Pattern from prompt_toolkit.completion import CompleteEvent, Completer, Completion from prompt_toolkit.completion.word_completer import WordCompleter @@ -28,10 +28,11 @@ class NestedCompleter(Completer): """ def __init__( - self, options: dict[str, Completer | None], ignore_case: bool = True + self, options: dict[str, Completer | None], ignore_case: bool = True, pattern: Pattern[str] | None = None ) -> None: self.options = options self.ignore_case = ignore_case + self.pattern = pattern def __repr__(self) -> str: return f"NestedCompleter({self.options!r}, ignore_case={self.ignore_case!r})" @@ -103,6 +104,6 @@ def get_completions( # No space in the input: behave exactly like `WordCompleter`. else: completer = WordCompleter( - list(self.options.keys()), ignore_case=self.ignore_case + list(self.options.keys()), ignore_case=self.ignore_case, pattern=self.pattern ) yield from completer.get_completions(document, complete_event) From 8509ca8158f08dea01a3a10eb83b7b9f65a67823 Mon Sep 17 00:00:00 2001 From: Gerardo Lecaros Date: Tue, 2 May 2023 13:31:24 -0700 Subject: [PATCH 2/3] sort --- src/prompt_toolkit/completion/nested.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prompt_toolkit/completion/nested.py b/src/prompt_toolkit/completion/nested.py index 16d4593c5..e4f1c1060 100644 --- a/src/prompt_toolkit/completion/nested.py +++ b/src/prompt_toolkit/completion/nested.py @@ -3,7 +3,7 @@ """ from __future__ import annotations -from typing import Any, Iterable, Mapping, Set, Union, Pattern +from typing import Any, Iterable, Mapping, Pattern, Set, Union from prompt_toolkit.completion import CompleteEvent, Completer, Completion from prompt_toolkit.completion.word_completer import WordCompleter From fd3a7eeef6a17a63358912870df7a733d8bf0d76 Mon Sep 17 00:00:00 2001 From: Gerardo Lecaros Date: Tue, 2 May 2023 15:58:05 -0700 Subject: [PATCH 3/3] reformatted with black --- src/prompt_toolkit/completion/nested.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/prompt_toolkit/completion/nested.py b/src/prompt_toolkit/completion/nested.py index e4f1c1060..25d13b883 100644 --- a/src/prompt_toolkit/completion/nested.py +++ b/src/prompt_toolkit/completion/nested.py @@ -28,7 +28,10 @@ class NestedCompleter(Completer): """ def __init__( - self, options: dict[str, Completer | None], ignore_case: bool = True, pattern: Pattern[str] | None = None + self, + options: dict[str, Completer | None], + ignore_case: bool = True, + pattern: Pattern[str] | None = None, ) -> None: self.options = options self.ignore_case = ignore_case @@ -104,6 +107,8 @@ def get_completions( # No space in the input: behave exactly like `WordCompleter`. else: completer = WordCompleter( - list(self.options.keys()), ignore_case=self.ignore_case, pattern=self.pattern + list(self.options.keys()), + ignore_case=self.ignore_case, + pattern=self.pattern, ) yield from completer.get_completions(document, complete_event)