diff --git a/docs/changelog.rst b/docs/changelog.rst index d65f0795a..64ba9f943 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,8 @@ To update |kitty|, :doc:`follow the instructions `. clicks to the application unless :opt:`terminal_select_modifiers` are pressed (:iss:`2368`) +- A new ``copy_and_clear_or_interrupt`` function (:iss:`2403`) + - X11: Fix arrow mouse cursor using right pointing instead of the default left pointing arrow (:iss:`2341`) diff --git a/kitty/config_data.py b/kitty/config_data.py index d8d7b32e4..11d4f018d 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -1159,7 +1159,8 @@ to zero for all mappings, including the builtin ones. g('shortcuts.clipboard') # {{{ k('copy_to_clipboard', 'kitty_mod+c', 'copy_to_clipboard', _('Copy to clipboard'), long_text=_(''' 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.''')) +It will copy only if there is a selection and send an interrupt otherwise. Similarly, :code:`copy_and_clear_or_interrupt` +will copy and clear the selection or send an interrupt if there is no selection.''')) if is_macos: k('copy_to_clipboard', 'cmd+c', 'copy_to_clipboard', _('Copy to clipboard'), add_to_docs=False) k('paste_from_clipboard', 'kitty_mod+v', 'paste_from_clipboard', _('Paste from clipboard')) diff --git a/kitty/screen.c b/kitty/screen.c index da333798c..d5d5a4a4a 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2048,6 +2048,12 @@ update_selection(Screen *self, PyObject *args) { Py_RETURN_NONE; } +static PyObject* +clear_selection(Screen *self, PyObject *args UNUSED) { + self->selection = EMPTY_SELECTION; + Py_RETURN_NONE; +} + WRAP0x(index) WRAP0(reverse_index) WRAP0(reset) @@ -2475,6 +2481,7 @@ static PyMethodDef methods[] = { MND(clear_tab_stop, METH_VARARGS) MND(start_selection, METH_VARARGS) MND(update_selection, METH_VARARGS) + MND(clear_selection, METH_NOARGS) MND(reverse_index, METH_NOARGS) MND(mark_as_dirty, METH_NOARGS) MND(resize, METH_VARARGS) diff --git a/kitty/window.py b/kitty/window.py index ee9cfabbf..2e329f74b 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -588,6 +588,10 @@ class Window: 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 copy_and_clear_or_interrupt(self): + self.copy_or_interrupt() + self.screen.clear_selection() + def pass_selection_to_program(self, *args): cwd = self.cwd_of_child text = self.text_for_selection()