From 699a38ae841b22dc5286621f9b8268ee39bb729c 2016-06-15 21:16:14 From: Matthias Bussonnier Date: 2016-06-15 21:16:14 Subject: [PATCH] Merge pull request #9614 from takluyver/win-paste-ctrlv Ctrl-V paste on Windows --- diff --git a/IPython/terminal/ptshell.py b/IPython/terminal/ptshell.py index 8c41af7..85c3a89 100644 --- a/IPython/terminal/ptshell.py +++ b/IPython/terminal/ptshell.py @@ -14,7 +14,9 @@ from IPython.utils.process import abbrev_cwd from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER, EditingMode -from prompt_toolkit.filters import HasFocus, HasSelection, Condition, ViInsertMode, EmacsInsertMode, IsDone, HasCompletions +from prompt_toolkit.filters import (HasFocus, HasSelection, Condition, + ViInsertMode, EmacsInsertMode, IsDone, HasCompletions) +from prompt_toolkit.filters.cli import ViMode from prompt_toolkit.history import InMemoryHistory from prompt_toolkit.shortcuts import create_prompt_application, create_eventloop, create_prompt_layout from prompt_toolkit.interface import CommandLineInterface @@ -271,6 +273,23 @@ class TerminalInteractiveShell(InteractiveShell): def _indent_buffer(event): event.current_buffer.insert_text(' ' * 4) + if sys.platform == 'win32': + from IPython.lib.clipboard import (ClipboardEmpty, + win32_clipboard_get, tkinter_clipboard_get) + @kbmanager.registry.add_binding(Keys.ControlV, + filter=(HasFocus(DEFAULT_BUFFER) & ~ViMode())) + def _paste(event): + try: + text = win32_clipboard_get() + except TryNext: + try: + text = tkinter_clipboard_get() + except (TryNext, ClipboardEmpty): + return + except ClipboardEmpty: + return + event.current_buffer.insert_text(text.replace('\t', ' ' * 4)) + # Pre-populate history from IPython's history database history = InMemoryHistory() last_cell = u""