|
22 | 22 | merge_formatted_text,
|
23 | 23 | )
|
24 | 24 | from prompt_toolkit.formatted_text.utils import fragment_list_width
|
| 25 | +from prompt_toolkit.key_binding.vi_state import InputMode |
25 | 26 | from prompt_toolkit.patch_stdout import patch_stdout as patch_stdout_context
|
26 | 27 | from prompt_toolkit.shortcuts import clear_title, print_formatted_text, set_title
|
27 | 28 | from prompt_toolkit.utils import DummyContext
|
@@ -70,9 +71,19 @@ def prompt() -> str:
|
70 | 71 | # This happens when the user used `asyncio.run()`.
|
71 | 72 | old_loop = None
|
72 | 73 |
|
| 74 | + # Capture the current input_mode in order to restore it after reset, |
| 75 | + # for ViState.reset() sets it to InputMode.INSERT unconditionally and |
| 76 | + # doesn't accept any arguments despite the docstring says otherwise. |
| 77 | + def pre_run(last_input_mode=self.app.vi_state.input_mode): |
| 78 | + if self.vi_keep_last_used_mode: |
| 79 | + self.app.vi_state.input_mode = last_input_mode |
| 80 | + |
| 81 | + if not self.vi_keep_last_used_mode and self.vi_start_in_nav_mode: |
| 82 | + self.app.vi_state.input_mode = InputMode.NAVIGATION |
| 83 | + |
73 | 84 | asyncio.set_event_loop(self.pt_loop)
|
74 | 85 | try:
|
75 |
| - return self.app.run() # inputhook=inputhook) |
| 86 | + return self.app.run(pre_run) # inputhook=inputhook) |
76 | 87 | finally:
|
77 | 88 | # Restore the original event loop.
|
78 | 89 | asyncio.set_event_loop(old_loop)
|
@@ -360,6 +371,10 @@ def get_locals():
|
360 | 371 | if configure:
|
361 | 372 | configure(repl)
|
362 | 373 |
|
| 374 | + # Set Vi input mode |
| 375 | + if repl.vi_start_in_nav_mode: |
| 376 | + repl.app.vi_state.input_mode = InputMode.NAVIGATION |
| 377 | + |
363 | 378 | # Start repl.
|
364 | 379 | patch_context: ContextManager = patch_stdout_context() if patch_stdout else DummyContext()
|
365 | 380 |
|
|
0 commit comments