diff --git a/kitty/boss.py b/kitty/boss.py index 1475bc375..f976b34a4 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1109,8 +1109,14 @@ class Boss: text = get_clipboard_string() self.paste_to_active_window(text) + def current_primary_selection(self) -> str: + return get_primary_selection() if supports_primary_selection else '' + + def current_primary_selection_or_clipboard(self) -> str: + return get_primary_selection() if supports_primary_selection else get_clipboard_string() + def paste_from_selection(self) -> None: - text = get_primary_selection() if supports_primary_selection else get_clipboard_string() + text = self.current_primary_selection_or_clipboard() self.paste_to_active_window(text) def set_primary_selection(self) -> None: diff --git a/kitty/config_data.py b/kitty/config_data.py index 0f1630a9f..517e0e495 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -659,13 +659,13 @@ Valid values are: :code:`arrow`, :code:`beam` and :code:`hand` g('mouse.mousemap') # {{{ m('click_url', 'ctrl+shift+left', 'release', 'grabbed,ungrabbed', 'mouse_click_url', _('Click the link under the mouse cursor')) -m('paste_selection', 'middle', 'release', 'grabbed,ungrabbed', 'paste_selection', _('Paste from the primary selection')) -m('extend_selection', 'right', 'press', 'grabbed,ungrabbed', 'mouse_selection extend', _('Extend the current selection')) + for grabbed in (False, True): modes = 'ungrabbed' + (',grabbed' if grabbed else '') name_s = '_grabbed' if grabbed else '' mods_p = 'shift+' if grabbed else '' ts = _(' even when grabbed') if grabbed else '' + m('paste_selection' + name_s, mods_p + 'middle', 'release', modes, 'paste_selection', _('Paste from the primary selection') + ts) m('start_simple_selection' + name_s, mods_p + 'left', 'press', modes, 'mouse_selection normal', _('Start selecting text') + ts) m('start_rectangle_selection' + name_s, mods_p + 'ctrl+alt+left', 'press', modes, 'mouse_selection rectangle', _('Start selecting text in a rectangle') + ts) @@ -675,6 +675,7 @@ for grabbed in (False, True): line_desc = _('Select the entire line. If you would rather select from the clicked' ' point to the end of the line, use ``line_at_point`` instead of ``line`` above') m('select_line' + name_s, mods_p + 'left', 'triplepress', modes, 'mouse_selection line', _('Select a line') + ts, line_desc) + m('extend_selection' + name_s, mods_p + 'right', 'press', modes, 'mouse_selection extend', _('Extend the current selection') + ts) # }}} # }}} diff --git a/kitty/window.py b/kitty/window.py index 94a48eb35..3bac9fa39 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -803,6 +803,16 @@ class Window: def mouse_selection(self, code: int) -> None: mouse_selection(self.os_window_id, self.tab_id, self.id, code, self.current_mouse_event_button) + + def paste_selection(self) -> None: + txt = get_boss().current_primary_selection() + if txt: + self.paste(txt) + + def paste_selection_or_clipboard(self) -> None: + txt = get_boss().current_primary_selection_or_clipboard() + if txt: + self.paste(txt) # }}} def text_for_selection(self) -> str: