Get middle click paste working and dont trigger when mouse is grabbed

This commit is contained in:
Kovid Goyal 2021-05-11 09:20:27 +05:30
parent 7a40959f13
commit 1e89cdc055
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 20 additions and 3 deletions

View file

@ -1109,8 +1109,14 @@ def paste_from_clipboard(self) -> None:
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:

View file

@ -659,13 +659,13 @@ def copy_on_select(raw: str) -> str:
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 @@ def copy_on_select(raw: str) -> str:
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)
# }}}
# }}}

View file

@ -803,6 +803,16 @@ def mouse_click_url(self) -> None:
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: