diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index 0ae89ba..a562502 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -16,7 +16,7 @@ from IPython.utils.process import abbrev_cwd from traitlets import Bool, CBool, Unicode, Dict from prompt_toolkit.completion import Completer, Completion -from prompt_toolkit.enums import DEFAULT_BUFFER +from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER from prompt_toolkit.filters import HasFocus, HasSelection, Condition from prompt_toolkit.history import InMemoryHistory from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop @@ -182,6 +182,13 @@ class TerminalInteractiveShell(InteractiveShell): def _(event): event.current_buffer.reset() + @kbmanager.registry.add_binding(Keys.ControlC, filter=HasFocus(SEARCH_BUFFER)) + def _(event): + if event.current_buffer.document.text: + event.current_buffer.reset() + else: + event.cli.push_focus(DEFAULT_BUFFER) + supports_suspend = Condition(lambda cli: hasattr(signal, 'SIGTSTP')) @kbmanager.registry.add_binding(Keys.ControlZ, filter=supports_suspend)