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

From: Alan Third <[email-masked]>
Date: Sun, 27 Sep 2020 10:59:32 +0100

On Sat, Sep 26, 2020 at 01:39:03PM +0200, Daniel Martín wrote:
> Alan Third <[email-masked]> writes:
> >
> > The big decision is what should Emacs do by default? My opinion is
> > that when receiving a URL we should insert the link as text rather
> > than try to open it: Emacs isn't a web browser. Perhaps that's wrong,
> > I'm not sure what Emacs does on other platforms.
> 
> I've tested on GNU/Linux (Emacs 27.1 and Emacs 24) and the behavior is
> that dragging an dropping a URL from Firefox opens the web page source,
> just like Emacs 26 on macOS. The GNU/Linux version does not seem to
> support overriding the destination action with Ctrl, Shift, etc.

I've been fiddling with this more and I've realised that (at least on
my machine today) Chrome and Safari never actually send the URLs as
NSPasteboardTypeURL, they just send them as plain text.

I suspect this means that if we want to support the NS drag and drop
process correctly (and I think we do) then we really need to look into
a larger rewrite, unfortunately. And any larger rewrite will need to
wait for Emacs 28, I think.

In the meantime I suppose the simplest work-around is something like
the attached, which is near enough the same as what you did, Daniel,
but making explicit that "copy" and "generic" are doing the same
thing.

-- 
Alan Third
>From 908a5fade4afc77467ef61b771c4e3c46c8cd798 Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Sun, 27 Sep 2020 10:55:32 +0100
Subject: [PATCH] Make drag and drop on NS open all URLs (bug#43470)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/term/ns-win.el (ns-drag-n-drop): Merge generic and copy
actions.

Co-authored-by: Daniel Martín <[email-masked]>
---
 lisp/term/ns-win.el | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
index 90024b001f..184271d9e6 100644
--- a/lisp/term/ns-win.el
+++ b/lisp/term/ns-win.el
@@ -513,15 +513,9 @@ 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)
-           ;; Try to open the file/URL.  If type is nil, try to open
-           ;; it as a URL anyway.
+    (cond ((or (memq 'ns-drag-operation-generic operations)
+               (memq 'ns-drag-operation-copy operations))
+           ;; Perform the default/copy action.
            (dolist (data objects)
              (dnd-handle-one-url window 'private (if (eq type 'file)
                                                      (concat "file:" data)
-- 
2.26.1