Skip to content

NestedCompleter doesn't work if there is a dash in the word #1280

Open
@famzah

Description

@famzah

If I have the word "multi-test", for example, auto-completion treats the dash "-" as a whitespace separator. It won't continue after "multi".

To fix this I used the following patch:

--- /usr/local/lib/python3.7/dist-packages/prompt_toolkit/completion/nested.py  2020-10-23 19:54:59.873439073 +0000
+++ NestedCompleterFixed.py     2020-10-25 14:40:35.306087935 +0000
@@ -7,6 +7,8 @@
 from prompt_toolkit.completion.word_completer import WordCompleter
 from prompt_toolkit.document import Document
 
+import re
+
 __all__ = ["NestedCompleter"]
 
 # NestedDict = Mapping[str, Union['NestedDict', Set[str], None, Completer]]
@@ -103,7 +105,8 @@
         # 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=re.compile(r'.*') # or else "-" breaks the completion
             )
             for c in completer.get_completions(document, complete_event):
                 yield c

I don't know if this is a correct fix but it works for me.

If this is the correct solution, then maybe you can add this as an argument in __init__().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions