summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2016-06-14 23:29:48 +0200
committerJonathan Slenders <jonathan@slenders.be>2016-06-14 23:29:48 +0200
commit51b6c8c0f7b618384961b37d4eb10d95fdfdbaa4 (patch)
tree5a2eca8818135c611b8632305d58b59726be801f
parent1f344012a4629a7ef54ddbf885bd36b68bec248c (diff)
Bugfix in get_common_complete_suffix. Don't return any suffix when there are completions that change whatever is before the cursor.
-rw-r--r--prompt_toolkit/completion.py9
-rw-r--r--prompt_toolkit/interface.py1
2 files changed, 7 insertions, 3 deletions
diff --git a/prompt_toolkit/completion.py b/prompt_toolkit/completion.py
index ede5b969..056274a1 100644
--- a/prompt_toolkit/completion.py
+++ b/prompt_toolkit/completion.py
@@ -120,13 +120,18 @@ def get_common_complete_suffix(document, completions):
end = completion.text[:-completion.start_position]
return document.text_before_cursor.endswith(end)
- completions = [c for c in completions if doesnt_change_before_cursor(c)]
+ completions2 = [c for c in completions if doesnt_change_before_cursor(c)]
+
+ # When there is at least one completion that changes the text before the
+ # cursor, don't return any common part.
+ if len(completions2) != len(completions):
+ return ''
# Return the common prefix.
def get_suffix(completion):
return completion.text[-completion.start_position:]
- return _commonprefix([get_suffix(c) for c in completions])
+ return _commonprefix([get_suffix(c) for c in completions2])
def _commonprefix(strings):
diff --git a/prompt_toolkit/interface.py b/prompt_toolkit/interface.py
index a320e84e..f1e4e696 100644
--- a/prompt_toolkit/interface.py
+++ b/prompt_toolkit/interface.py
@@ -779,7 +779,6 @@ class CommandLineInterface(object):
complete_thread_running[0] = False
# When there is only one completion, which has nothing to add, ignore it.
- text_before_cursor = document.text_before_cursor
if (len(completions) == 1 and
completion_does_nothing(document, completions[0])):
del completions[:]