Subject: Re: bug#43470: 27.1; Drag and Drop not working properly in 27.1 on OSX

From: Daniel Martín <[email-masked]>
Date: Sat, 19 Sep 2020 14:45:19 +0200

"Paul Magwene, Ph.D." <[email-masked]> writes:
>
> My testing suggests that there's still source application specific behavior.
>
> * Simple drag of images works when Safari or Chrome is the web browser.
>
> * No combination of Option, Command, or Control seems to work in Firefox; the drag behavior always produces a URL.
>
> So I guess the patch partially fixes the regression.  Given the state
> of the OS X api I'm not sure what the best way forward is. I'd try and
> jump in to contribute but I unfortunately have zero experience working
> with Objective C or programming against Apple's APIs
>
> Best,
> Paul

OK, I've created a patch on top of emacs-27. I've tested it by dragging
and dropping files, text, URLs, images, from Safari and Firefox, and I
get the same default behavior as in Emacs 26.3. Note that you should
still be able to override the default behavior by pressing Option,
Command, etc. while dragging the content.

Could you test it and see if it completely fixes the drag and drop
behavior on macOS?

Thanks.

>From 1a41df947bcf102e0884f295d8f394ade8d9eb18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <[email-masked]>
Date: Sat, 19 Sep 2020 14:13:53 +0200
Subject: [PATCH] Give ns-drag-operation-copy preference when handling drag and
 drop

Some applications like Firefox send NSDragOperationEvery when dragging
URLs or images. That constant means "every possible operation (copy,
link, move)". When there's more than one operation, we want to
consider specialized actions like ns-drag-operation-copy before
generic ones like ns-drag-operation-generic.

This change brings back the same drag and drop behavior as in Emacs
26.3. (Bug#43470).

* lisp/term/ns-win.el (ns-drag-n-drop): Move the check for
ns-drag-operation-copy before ns-drag-operation-generic.
---
 lisp/term/ns-win.el | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
index 90024b001f..fc20de5a05 100644
--- a/lisp/term/ns-win.el
+++ b/lisp/term/ns-win.el
@@ -513,19 +513,19 @@ ns-drag-n-drop
     (set-frame-selected-window nil window)
     (raise-frame)
     (setq window (selected-window))
-    (cond ((memq 'ns-drag-operation-generic operations)
-           ;; Perform the default action for the type.
-           (if (eq type 'file)
-               (dolist (data objects)
-                 (dnd-handle-one-url window 'private (concat "file:" data)))
-             (dnd-insert-text window 'private string)))
-          ((memq 'ns-drag-operation-copy operations)
+    (cond ((memq 'ns-drag-operation-copy operations)
            ;; Try to open the file/URL.  If type is nil, try to open
            ;; it as a URL anyway.
            (dolist (data objects)
              (dnd-handle-one-url window 'private (if (eq type 'file)
                                                      (concat "file:" data)
                                                    data))))
+          ((memq 'ns-drag-operation-generic operations)
+           ;; Perform the default action for the type.
+           (if (eq type 'file)
+               (dolist (data objects)
+                 (dnd-handle-one-url window 'private (concat "file:" data)))
+             (dnd-insert-text window 'private string)))
           (t
            ;; Insert the text as is.
            (dnd-insert-text window 'private string)))))
-- 
2.28.0