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
3 changed files with 17 additions and 2 deletions
+10 -1
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()