##// END OF EJS Templates
makes dictionary key completion use same delimiters as splitter
Jeff Hussmann -
Show More
@@ -416,7 +416,7 b' def get__all__entries(obj):'
416 return [w for w in words if isinstance(w, string_types)]
416 return [w for w in words if isinstance(w, string_types)]
417
417
418
418
419 def match_dict_keys(keys, prefix):
419 def match_dict_keys(keys, prefix, delims):
420 """Used by dict_key_matches, matching the prefix to a list of keys"""
420 """Used by dict_key_matches, matching the prefix to a list of keys"""
421 if not prefix:
421 if not prefix:
422 return None, 0, [repr(k) for k in keys
422 return None, 0, [repr(k) for k in keys
@@ -427,8 +427,9 b' def match_dict_keys(keys, prefix):'
427 prefix_str = eval(prefix + quote, {})
427 prefix_str = eval(prefix + quote, {})
428 except Exception:
428 except Exception:
429 return None, 0, []
429 return None, 0, []
430
430
431 token_match = re.search(r'\w*$', prefix, re.UNICODE)
431 pattern = '[^' + ''.join('\\' + c for c in delims) + ']*$'
432 token_match = re.search(pattern, prefix, re.UNICODE)
432 token_start = token_match.start()
433 token_start = token_match.start()
433 token_prefix = token_match.group()
434 token_prefix = token_match.group()
434
435
@@ -913,7 +914,7 b' class IPCompleter(Completer):'
913 keys = get_keys(obj)
914 keys = get_keys(obj)
914 if not keys:
915 if not keys:
915 return keys
916 return keys
916 closing_quote, token_offset, matches = match_dict_keys(keys, prefix)
917 closing_quote, token_offset, matches = match_dict_keys(keys, prefix, self.splitter.delims)
917 if not matches:
918 if not matches:
918 return matches
919 return matches
919
920
@@ -490,6 +490,11 b' def test_dict_key_completion_string():'
490 _, matches = complete(line_buffer="d[\"a'")
490 _, matches = complete(line_buffer="d[\"a'")
491 nt.assert_in("b", matches)
491 nt.assert_in("b", matches)
492
492
493 # need to not split at delims that readline won't split at
494 if '-' not in ip.Completer.splitter.delims:
495 ip.user_ns['d'] = {'before-after': None}
496 _, matches = complete(line_buffer="d['before-af")
497 nt.assert_in('before-after', matches)
493
498
494 def test_dict_key_completion_contexts():
499 def test_dict_key_completion_contexts():
495 """Test expression contexts in which dict key completion occurs"""
500 """Test expression contexts in which dict key completion occurs"""
General Comments 0
You need to be logged in to leave comments. Login now