diff --git a/docs/changelog.rst b/docs/changelog.rst index f746c08d1..1f2535afb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,9 @@ To update |kitty|, :doc:`follow the instructions `. - Support for an arbitrary number of internal clipboard buffers to copy/paste from, see (:ref:`cpbuf`) +- Allow using the new private internal clipboard buffers with the + :opt:`copy_on_select` option (:iss:`1390`) + - macOS: Allow opening new kitty tabs/top-level windows from Finder (:pull:`1350`) diff --git a/kitty/boss.py b/kitty/boss.py index c59e46289..6ca3d35b4 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -813,7 +813,7 @@ class Boss: if text: set_primary_selection(text) if self.opts.copy_on_select: - set_clipboard_string(text) + self.copy_to_buffer(self.opts.copy_on_select) def copy_to_buffer(self, buffer_name): w = self.active_window diff --git a/kitty/config_data.py b/kitty/config_data.py index e8cc1ff90..4f13ae6fe 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -393,12 +393,31 @@ The program with which to open URLs that are clicked on. The special value :code:`default` means to use the operating system's default URL handler.''')) -o('copy_on_select', False, long_text=_(''' -Copy to clipboard on select. With this enabled, simply selecting text with -the mouse will cause the text to be copied to clipboard. Useful on platforms -such as macOS that do not have the concept of primary selections. Note -that this is a security risk, as all programs, including websites open in your -browser can read the contents of the clipboard.''')) + +def copy_on_select(raw): + q = raw.lower() + # boolean values special cased for backwards compat + if q in ('y', 'yes', 'true', 'clipboard'): + return 'clipboard' + if q in ('n', 'no', 'false', ''): + return '' + return raw + + +o('copy_on_select', 'no', option_type=copy_on_select, long_text=_(''' +Copy to clipboard or a private buffer on select. With this set to +:code:`clipboard`, simply selecting text with the mouse will cause the text to +be copied to clipboard. Useful on platforms such as macOS that do not have the +concept of primary selections. You can instead specify a name such as :code:`a1` to +copy to a private kitty buffer instead. Map a shortcut with the +:code:`paste_from_buffer` action to paste from this private buffer. +For example:: + + map cmd+shift+v paste_from_buffer a1 + +Note that copying to the clipboard is a security risk, as all programs, +including websites open in your browser can read the contents of the +system clipboard.''')) o('strip_trailing_spaces', 'never', option_type=choices('never', 'smart', 'always'), long_text=_(''' Remove spaces at the end of lines when copying to clipboard. diff --git a/kitty/window.py b/kitty/window.py index d5ac00c96..d087a3351 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -440,7 +440,7 @@ class Window: if 'write-clipboard' in self.opts.clipboard_control: write('c', set_clipboard_string) if 'p' in where: - if self.opts.copy_on_select: + if self.opts.copy_on_select == 'clipboard': if 'write-clipboard' in self.opts.clipboard_control: write('c', set_clipboard_string) if 'write-primary' in self.opts.clipboard_control: