Add a new `copy_or_interrupt action that can be mapped to kbd:ctrl+c`. It will copy if there is a selection and interrupt otherwise

Fixes #1286
This commit is contained in:
Kovid Goyal 2019-01-04 09:21:29 +05:30
parent 50a6abaac1
commit ed905fcf6d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 17 additions and 2 deletions

View File

@ -17,6 +17,9 @@ Changelog
`*_with_cwd` actions that open a new window with the current working
directory.
- Add a new ``copy_or_interrupt`` action that can be mapped to kbd:`ctrl+c`. It
will copy if there is a selection and interrupt otherwise (:iss:`1286`)
- Fix setting :opt:`background_opacity` causing window margins/padding to be slightly
different shade from background (:iss:`1221`)

View File

@ -848,7 +848,10 @@ g('shortcuts.clipboard') # {{{
if is_macos:
k('copy_to_clipboard', 'cmd+c', 'copy_to_clipboard', _('Copy to clipboard'), add_to_docs=False)
k('paste_from_clipboard', 'cmd+v', 'paste_from_clipboard', _('Paste from clipboard'), add_to_docs=False)
k('copy_to_clipboard', 'kitty_mod+c', 'copy_to_clipboard', _('Copy to clipboard'))
k('copy_to_clipboard', 'kitty_mod+c', 'copy_to_clipboard', _(
'Copy to clipboard. There is also a :code:`copy_or_interrupt` action that'
' can be optionally mapped to :kbd:`ctrl+c`. It'
' will copy only if there is a selection and send an interrupt otherwise. '))
k('paste_from_clipboard', 'kitty_mod+v', 'paste_from_clipboard', _('Paste from clipboard'))
k('paste_from_selection', 'kitty_mod+s', 'paste_from_selection', _('Paste from selection'))
k('paste_from_selection', 'shift+insert', 'paste_from_selection', _('Paste from selection'))

View File

@ -23,7 +23,7 @@ from .fast_data_types import (
set_clipboard_string, set_titlebar_color, set_window_render_data,
update_window_title, update_window_visibility, viewport_for_window
)
from .keys import keyboard_mode_name
from .keys import keyboard_mode_name, extended_key_event, defines
from .rgb import to_color
from .terminfo import get_capabilities
from .utils import (
@ -524,6 +524,15 @@ class Window:
if text:
set_clipboard_string(text)
def copy_or_interrupt(self):
text = self.text_for_selection()
if text:
set_clipboard_string(text)
else:
mode = keyboard_mode_name(self.screen)
text = extended_key_event(defines.GLFW_KEY_C, defines.GLFW_MOD_CONTROL, defines.GLFW_PRESS) if mode == 'kitty' else b'\x03'
self.write_to_child(text)
def pass_selection_to_program(self, *args):
cwd = self.cwd_of_child
text = self.text_for_selection()