##// END OF EJS Templates
Bugfix: when doing \dot completion. Compose unicode character from completion.
Jonathan Slenders -
Show More
@@ -4,7 +4,9 b' from __future__ import print_function'
4 import os
4 import os
5 import sys
5 import sys
6 import signal
6 import signal
7 import unicodedata
7 from warnings import warn
8 from warnings import warn
9 from wcwidth import wcwidth
8
10
9 from IPython.core.error import TryNext
11 from IPython.core.error import TryNext
10 from IPython.core.interactiveshell import InteractiveShell
12 from IPython.core.interactiveshell import InteractiveShell
@@ -35,7 +37,6 b' from .pt_inputhooks import get_inputhook_func'
35 from .interactiveshell import get_default_editor, TerminalMagics
37 from .interactiveshell import get_default_editor, TerminalMagics
36
38
37
39
38
39 class IPythonPTCompleter(Completer):
40 class IPythonPTCompleter(Completer):
40 """Adaptor to provide IPython completions to prompt_toolkit"""
41 """Adaptor to provide IPython completions to prompt_toolkit"""
41 def __init__(self, ipy_completer):
42 def __init__(self, ipy_completer):
@@ -51,6 +52,22 b' class IPythonPTCompleter(Completer):'
51 )
52 )
52 start_pos = -len(used)
53 start_pos = -len(used)
53 for m in matches:
54 for m in matches:
55 m = unicodedata.normalize('NFC', m)
56
57 # When the first character of the completion has a zero length,
58 # then it's probably a decomposed unicode character. E.g. caused by
59 # the "\dot" completion. Try to compose again with the previous
60 # character.
61 if wcwidth(m[0]) == 0:
62 if document.cursor_position + start_pos > 0:
63 char_before = document.text[document.cursor_position + start_pos - 1]
64 m = unicodedata.normalize('NFC', char_before + m)
65
66 # Yield the modified completion instead, if this worked.
67 if wcwidth(m[0:1]) == 1:
68 yield Completion(m, start_position=start_pos - 1)
69 continue
70
54 yield Completion(m, start_position=start_pos)
71 yield Completion(m, start_position=start_pos)
55
72
56
73
General Comments 0
You need to be logged in to leave comments. Login now