File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -49,15 +49,15 @@ def autocomplete(self, line):
49
49
# The user has hit backspace. We'll need to check
50
50
# the current words.
51
51
return self ._handle_backspace ()
52
+ elif not line :
53
+ return []
52
54
elif current_length != self ._last_position + 1 :
53
55
return self ._complete_from_full_parse ()
54
56
55
57
# This position is important. We only update the _last_position
56
58
# after we've checked the special cases above where that value
57
59
# matters.
58
60
self ._last_position = len (line )
59
- if not line :
60
- return []
61
61
if line and not line .strip ():
62
62
# Special case, the user hits a space on a new line so
63
63
# we autocomplete all the top level commands.
Original file line number Diff line number Diff line change @@ -337,3 +337,20 @@ def test_last_option_is_updated_on_global_options(index_data):
337
337
assert completer .last_option == '--resources'
338
338
completer .autocomplete ('ec2 create-tags --resources f --no-sign-request ' )
339
339
assert completer .last_option == '--no-sign-request'
340
+
341
+
342
+ def test_can_handle_autocompleting_same_string_twice (index_data ):
343
+ index_data ['aws' ]['commands' ] = ['first' , 'second' ]
344
+ completer = AWSCLIModelCompleter (index_data )
345
+ completer .autocomplete ('f' )
346
+ assert completer .autocomplete ('f' ) == ['first' ]
347
+
348
+
349
+ def test_can_handle_autocomplete_empty_string_twice (index_data ):
350
+ # Sometimes prompt_toolkit will try to autocomplete
351
+ # the empty string multiple times. We need to handle this
352
+ # gracefully.
353
+ index_data ['aws' ]['commands' ] = ['first' , 'second' ]
354
+ completer = AWSCLIModelCompleter (index_data )
355
+ assert completer .autocomplete ('' ) == []
356
+ assert completer .autocomplete ('' ) == []
You can’t perform that action at this time.
0 commit comments