emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 2289fafeaf: Fix `clipboard-yank' inserting off the kill ring inst


From: Po Lu
Subject: master 2289fafeaf: Fix `clipboard-yank' inserting off the kill ring instead of CLIPBOARD
Date: Thu, 30 Jun 2022 22:23:25 -0400 (EDT)

branch: master
commit 2289fafeaf4dc21c0c9751a3a195d855bf5e91f8
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Fix `clipboard-yank' inserting off the kill ring instead of CLIPBOARD
    
    * lisp/select.el (gui-last-cut-in-clipboard)
    (gui-last-cut-in-primary): New variables.
    (gui-select-text): Set those variables.
    (gui--selection-value-internal, gui-selection-value): Don't
    return nil if the last cut did not own the chosen
    selection.  (bug#56325)
---
 lisp/select.el | 46 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/lisp/select.el b/lisp/select.el
index 8ffe16e7b3..d977a8714b 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -112,20 +112,28 @@ E.g. it doesn't exist under MS-Windows."
 ;; We keep track of the last selection here, so we can check the
 ;; current selection against it, and avoid passing back with
 ;; gui-selection-value the same text we previously killed or
-;; yanked. We track both
-;; separately in case another X application only sets one of them
-;; we aren't fooled by the PRIMARY or CLIPBOARD selection staying the same.
+;; yanked. We track both separately in case another X application only
+;; sets one of them we aren't fooled by the PRIMARY or CLIPBOARD
+;; selection staying the same.
 
 (defvar gui--last-selected-text-clipboard nil
   "The value of the CLIPBOARD selection last seen.")
+
 (defvar gui--last-selected-text-primary nil
   "The value of the PRIMARY selection last seen.")
 
 (defvar gui--last-selection-timestamp-clipboard nil
   "The timestamp of the CLIPBOARD selection last seen.")
+
 (defvar gui--last-selection-timestamp-primary nil
   "The timestamp of the PRIMARY selection last seen.")
 
+(defvar gui-last-cut-in-clipboard nil
+  "Whether or not the last call to `interprogram-cut-function' owned 
CLIPBOARD.")
+
+(defvar gui-last-cut-in-primary nil
+  "Whether or not the last call to `interprogram-cut-function' owned PRIMARY.")
+
 (defun gui--set-last-clipboard-selection (text)
   "Save last clipboard selection.
 Save the selected text, passed as argument, and for window
@@ -182,7 +190,10 @@ MS-Windows does not have a \"primary\" selection."
     ;; should not be reset by cut (Bug#16382).
     (setq saved-region-selection text)
     (gui-set-selection 'CLIPBOARD text)
-    (gui--set-last-clipboard-selection text)))
+    (gui--set-last-clipboard-selection text))
+  ;; Record which selections we now have ownership over.
+  (setq gui-last-cut-in-clipboard select-enable-clipboard
+        gui-last-cut-in-primary select-enable-primary))
 (define-obsolete-function-alias 'x-select-text 'gui-select-text "25.1")
 
 (defcustom x-select-request-type nil
@@ -218,13 +229,13 @@ decided by `x-select-request-type'.  The return value is 
already
 decoded.  If `gui-get-selection' signals an error, return nil."
   ;; The doc string of `interprogram-paste-function' says to return
   ;; nil if no other program has provided text to paste.
-  (unless (and
-           ;; `gui-backend-selection-owner-p' might be unreliable on
-           ;; some other window systems.
-           (memq window-system '(x haiku))
-           (eq type 'CLIPBOARD)
-           ;; Should we unify this with gui--clipboard-selection-unchanged-p?
-           (gui-backend-selection-owner-p type))
+  (unless (and gui-last-cut-in-clipboard
+               ;; `gui-backend-selection-owner-p' might be unreliable on
+               ;; some other window systems.
+               (memq window-system '(x haiku))
+               (eq type 'CLIPBOARD)
+               ;; Should we unify this with 
gui--clipboard-selection-unchanged-p?
+               (gui-backend-selection-owner-p type))
     (let ((request-type (if (memq window-system '(x pgtk haiku))
                             (or x-select-request-type
                                 '(UTF8_STRING COMPOUND_TEXT STRING 
text/plain\;charset=utf-8))
@@ -254,7 +265,15 @@ decoded.  If `gui-get-selection' signals an error, return 
nil."
              ;; (bug#53894) for further discussion about this DWIM
              ;; action, and possible ways to make this check less
              ;; fragile, if so desired.
-             (unless (gui--clipboard-selection-unchanged-p text)
+
+             ;; Don't check the "newness" of CLIPBOARD if the last
+             ;; call to `gui-select-text' didn't cause us to become
+             ;; its owner.  This lets the user yank text killed by
+             ;; `clipboard-kill-region' with `clipboard-yank' without
+             ;; interference from text killed by other means when
+             ;; `select-enable-clipboard' is nil.
+             (unless (and gui-last-cut-in-clipboard
+                          (gui--clipboard-selection-unchanged-p text))
                (gui--set-last-clipboard-selection text)
                text))))
         (primary-text
@@ -264,7 +283,8 @@ decoded.  If `gui-get-selection' signals an error, return 
nil."
              ;; Check the PRIMARY selection for 'newness', is it different
              ;; from what we remembered them to be last time we did a
              ;; cut/paste operation.
-             (unless (gui--primary-selection-unchanged-p text)
+             (unless (and gui-last-cut-in-primary
+                          (gui--primary-selection-unchanged-p text))
                (gui--set-last-primary-selection text)
                text)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]