@@ -512,15 +512,18 @@ def cw(self):
512
512
# isn't at the end of the line, but that's what this does for now.
513
513
if self .cpos : return
514
514
515
- # look from right to left for a bad method character
515
+ # look from right to left for a bad method or dictionary character
516
516
l = len (self .s )
517
517
is_method_char = lambda c : c .isalnum () or c in ('.' , '_' )
518
+ dict_chars = ['[' ]
518
519
519
- if not self .s or not is_method_char (self .s [l - 1 ]):
520
+ if not self .s or not (is_method_char (self .s [- 1 ])
521
+ or self .s [- 1 ] in dict_chars ):
520
522
return
521
523
522
524
for i in range (1 , l + 1 ):
523
- if not is_method_char (self .s [- i ]):
525
+ c = self .s [- i ]
526
+ if not (is_method_char (c ) or c in dict_chars ):
524
527
i -= 1
525
528
break
526
529
@@ -1281,15 +1284,22 @@ def show_list(self, items, topline=None, current_item=None):
1281
1284
max_h = y + 1
1282
1285
max_w = int (w * self .config .cli_suggestion_width )
1283
1286
self .list_win .erase ()
1287
+
1284
1288
if items :
1285
1289
sep = '.'
1286
- if os .path .sep in items [0 ]:
1287
- # Filename completion
1288
- sep = os .path .sep
1289
- if sep in items [0 ]:
1290
- items = [x .rstrip (sep ).rsplit (sep )[- 1 ] for x in items ]
1290
+ separators = ['.' , os .path .sep , '[' ]
1291
+ lastindex = max ([items [0 ].rfind (c ) for c in separators ])
1292
+ if lastindex > - 1 :
1293
+ sep = items [0 ][lastindex ]
1294
+ items = [x .rstrip (sep ).rsplit (sep )[- 1 ] for x in items ]
1295
+ if current_item :
1296
+ current_item = current_item .rstrip (sep ).rsplit (sep )[- 1 ]
1297
+
1298
+ if items [0 ].endswith (']' ):
1299
+ # dictionary key suggestions
1300
+ items = [x .rstrip (']' ) for x in items ]
1291
1301
if current_item :
1292
- current_item = current_item .rstrip (sep ). rsplit ( sep )[ - 1 ]
1302
+ current_item = current_item .rstrip (']' )
1293
1303
1294
1304
if topline :
1295
1305
height_offset = self .mkargspec (topline , down ) + 1
0 commit comments