##// END OF EJS Templates
makes dictionary key completion use same delimiters as splitter
Jeff Hussmann -
Show More
@@ -418,7 +418,7 b' def get__all__entries(obj):'
418 418 return [w for w in words if isinstance(w, string_types)]
419 419
420 420
421 def match_dict_keys(keys, prefix):
421 def match_dict_keys(keys, prefix, delims):
422 422 """Used by dict_key_matches, matching the prefix to a list of keys"""
423 423 if not prefix:
424 424 return None, 0, [repr(k) for k in keys
@@ -429,8 +429,9 b' def match_dict_keys(keys, prefix):'
429 429 prefix_str = eval(prefix + quote, {})
430 430 except Exception:
431 431 return None, 0, []
432
433 token_match = re.search(r'\w*$', prefix, re.UNICODE)
432
433 pattern = '[^' + ''.join('\\' + c for c in delims) + ']*$'
434 token_match = re.search(pattern, prefix, re.UNICODE)
434 435 token_start = token_match.start()
435 436 token_prefix = token_match.group()
436 437
@@ -973,7 +974,7 b' class IPCompleter(Completer):'
973 974 keys = get_keys(obj)
974 975 if not keys:
975 976 return keys
976 closing_quote, token_offset, matches = match_dict_keys(keys, prefix)
977 closing_quote, token_offset, matches = match_dict_keys(keys, prefix, self.splitter.delims)
977 978 if not matches:
978 979 return matches
979 980
@@ -530,6 +530,11 b' def test_dict_key_completion_string():'
530 530 _, matches = complete(line_buffer="d[\"a'")
531 531 nt.assert_in("b", matches)
532 532
533 # need to not split at delims that readline won't split at
534 if '-' not in ip.Completer.splitter.delims:
535 ip.user_ns['d'] = {'before-after': None}
536 _, matches = complete(line_buffer="d['before-af")
537 nt.assert_in('before-after', matches)
533 538
534 539 def test_dict_key_completion_contexts():
535 540 """Test expression contexts in which dict key completion occurs"""
General Comments 0
You need to be logged in to leave comments. Login now