##// END OF EJS Templates
Merge pull request #7506 from minrk/character-offset...
Thomas Kluyver -
r20029:150d15d3 merge
parent child Browse files
Show More
@@ -11,6 +11,7 b' except ImportError:'
11
11
12 from IPython.config import Configurable
12 from IPython.config import Configurable
13 from IPython.core.completer import IPCompleter
13 from IPython.core.completer import IPCompleter
14 from IPython.utils.py3compat import str_to_unicode, unicode_to_str, cast_bytes, cast_unicode
14 from IPython.utils.traitlets import Float
15 from IPython.utils.traitlets import Float
15 import IPython.utils.rlineimpl as readline
16 import IPython.utils.rlineimpl as readline
16
17
@@ -36,8 +37,13 b' class ZMQCompleter(IPCompleter):'
36 self.readline.set_completer_delims('\r\n')
37 self.readline.set_completer_delims('\r\n')
37
38
38 def complete_request(self, text):
39 def complete_request(self, text):
39 line = readline.get_line_buffer()
40 line = str_to_unicode(readline.get_line_buffer())
40 cursor_pos = readline.get_endidx()
41 byte_cursor_pos = readline.get_endidx()
42
43 # get_endidx is a byte offset
44 # account for multi-byte characters to get correct cursor_pos
45 bytes_before_cursor = cast_bytes(line)[:byte_cursor_pos]
46 cursor_pos = len(cast_unicode(bytes_before_cursor))
41
47
42 # send completion request to kernel
48 # send completion request to kernel
43 # Give the kernel up to 5s to respond
49 # Give the kernel up to 5s to respond
@@ -54,6 +60,7 b' class ZMQCompleter(IPCompleter):'
54 if content["cursor_end"] < cursor_pos:
60 if content["cursor_end"] < cursor_pos:
55 extra = line[content["cursor_end"]: cursor_pos]
61 extra = line[content["cursor_end"]: cursor_pos]
56 matches = [m + extra for m in matches]
62 matches = [m + extra for m in matches]
63 matches = [ unicode_to_str(m) for m in matches ]
57 return matches
64 return matches
58 return []
65 return []
59
66
General Comments 0
You need to be logged in to leave comments. Login now