|
5 | 5 |
|
6 | 6 | from IPython.core.completer import IPCompleter |
7 | 7 | from .ptutils import IPythonPTCompleter |
8 | | -from .shortcuts import suspend_to_bg |
| 8 | +from .shortcuts import suspend_to_bg, cursor_in_leading_ws |
9 | 9 |
|
10 | | -from prompt_toolkit.filters import Condition |
| 10 | +from prompt_toolkit.enums import DEFAULT_BUFFER |
| 11 | +from prompt_toolkit.filters import (Condition, HasFocus, HasSelection, |
| 12 | + ViInsertMode, EmacsInsertMode) |
11 | 13 | from prompt_toolkit.keys import Keys |
12 | 14 | from prompt_toolkit.key_binding.manager import KeyBindingManager |
| 15 | +from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline |
13 | 16 | from prompt_toolkit.token import Token |
14 | 17 | from prompt_toolkit.shortcuts import create_prompt_application |
15 | 18 | from prompt_toolkit.interface import CommandLineInterface |
@@ -42,14 +45,24 @@ def patch_stdout(**kwargs): |
42 | 45 | kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend |
43 | 46 | )(suspend_to_bg) |
44 | 47 |
|
| 48 | + if self.shell.display_completions == 'readlinelike': |
| 49 | + kbmanager.registry.add_binding(Keys.ControlI, |
| 50 | + filter=(HasFocus(DEFAULT_BUFFER) |
| 51 | + & ~HasSelection() |
| 52 | + & ViInsertMode() | EmacsInsertMode() |
| 53 | + & ~cursor_in_leading_ws |
| 54 | + ))(display_completions_like_readline) |
| 55 | + multicolumn = (self.shell.display_completions == 'multicolumn') |
| 56 | + |
45 | 57 | self._pt_app = create_prompt_application( |
46 | 58 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), |
47 | 59 | key_bindings_registry=kbmanager.registry, |
48 | 60 | history=self.shell.debugger_history, |
49 | 61 | completer= self._ptcomp, |
50 | 62 | enable_history_search=True, |
51 | 63 | mouse_support=self.shell.mouse_support, |
52 | | - get_prompt_tokens=get_prompt_tokens |
| 64 | + get_prompt_tokens=get_prompt_tokens, |
| 65 | + display_completions_in_columns=multicolumn, |
53 | 66 | ) |
54 | 67 | self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop) |
55 | 68 |
|
|
0 commit comments