diff options
author | Jonathan Slenders <jonathan@slenders.be> | 2016-06-08 20:51:28 +0200 |
---|---|---|
committer | Jonathan Slenders <jonathan@slenders.be> | 2016-06-08 20:51:28 +0200 |
commit | 1be9ddd77784df236aab140d51994a8aaef161c0 (patch) | |
tree | e9dd3d0a2a54a761677c8897cd000aa4bbb86c4c | |
parent | cbbcbc1bea5fec57e1f63ef5414fc24456824518 (diff) |
Don't apply completions, if there is only one completion which doesn't have any effect.
-rw-r--r-- | prompt_toolkit/interface.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/prompt_toolkit/interface.py b/prompt_toolkit/interface.py index 2d0b01c2..a320e84e 100644 --- a/prompt_toolkit/interface.py +++ b/prompt_toolkit/interface.py @@ -740,6 +740,16 @@ class CommandLineInterface(object): """ complete_thread_running = [False] # By ref. + def completion_does_nothing(document, completion): + """ + Return `True` if applying this completion doesn't have any effect. + (When it doesn't insert any new text. + """ + text_before_cursor = document.text_before_cursor + replaced_text = text_before_cursor[ + len(text_before_cursor) + completion.start_position:] + return replaced_text == completion.text + def async_completer(select_first=False, select_last=False, insert_common_part=False, complete_event=None): document = buffer.document @@ -768,6 +778,12 @@ 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[:] + # Set completions if the text was not yet changed. if buffer.text == document.text and \ buffer.cursor_position == document.cursor_position and \ |