summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2016-06-01 22:28:35 +0200
committerJonathan Slenders <jonathan@slenders.be>2016-06-01 22:28:35 +0200
commit3d058796c0b6981f95d6c07c4b7970c4db12bbd8 (patch)
tree02f4205a8cd76a89738a659f4f82e7af5959689c
parent3e17fdf2f2aa3da8778365f3a62b6bcae204c60b (diff)
Small improvement to the autocomplete code: thread safety.
-rw-r--r--prompt_toolkit/interface.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/prompt_toolkit/interface.py b/prompt_toolkit/interface.py
index f4c685db..2d0b01c2 100644
--- a/prompt_toolkit/interface.py
+++ b/prompt_toolkit/interface.py
@@ -758,7 +758,6 @@ class CommandLineInterface(object):
def run():
completions = list(buffer.completer.get_completions(document, complete_event))
- complete_thread_running[0] = False
def callback():
"""
@@ -767,6 +766,8 @@ class CommandLineInterface(object):
pressed 'Tab' in the meantime. Also don't set it if the text
was changed in the meantime.
"""
+ complete_thread_running[0] = False
+
# Set completions if the text was not yet changed.
if buffer.text == document.text and \
buffer.cursor_position == document.cursor_position and \
@@ -800,7 +801,7 @@ class CommandLineInterface(object):
go_to_first=select_first or select_first_anyway,
go_to_last=select_last)
self.invalidate()
- else:
+ elif not buffer.complete_state:
# Otherwise, restart thread.
async_completer()
@@ -833,9 +834,10 @@ class CommandLineInterface(object):
def run():
suggestion = buffer.auto_suggest.get_suggestion(self, buffer, document)
- suggest_thread_running[0] = False
def callback():
+ suggest_thread_running[0] = False
+
# Set suggestion only if the text was not yet changed.
if buffer.text == document.text and \
buffer.cursor_position == document.cursor_position: