Subject: Re: bug#30929: 26.0.91; Text drag and drop does not work

From: Nick Helm <[email-masked]>
Date: Thu, 12 Apr 2018 17:34:17 +1200

On Wed, 11 Apr 2018 at 07:38:24 +1200, Alan Third wrote:

> On Mon, Apr 09, 2018 at 01:51:58PM +1200, Nick Helm wrote:

> This is probably a better idea, we pass the string, the type (from the
> PB) and the mask to lisp, and then let ns-drag-n-drop sort it out.
> Like you say, if an expert wants to do something different they can
> then write their own function.
>
> So in C we just construct something like:
>
>     '(file
>       (ns-drag-operation-copy
>        ns-drag-operation-link)
>       "filename")
>
> Are you wanting to give this a go? I’m happy to work on it if not.

Ok, I see what you mean. Yep, I can have a go at it.

> I’m not sure what the deal is with drag‐n‐drop from Emacs on
> GNU/Linux, but assuming it works under GNUstep as well as Cocoa we
> could add Emacs as a drag source.

I'll check. There may also be some technical hurdle, but I'd like to
have a go at this too. The docs for NSDraggingSource make it sound so
easy...

>> I'm guessing the boat has well and truly sailed for such major tweaks
>> in Emacs 26 though. Instead, would it make sense to change the
>> default binding on macOS so at least basic (unmodified) text dnd
>> works out of the box for the upcoming release?

> What would we have to do, just change the default bindings in
> ns-win.el?
>
> (global-set-key [drag-n-drop] 'ns-drag-n-drop)
> (global-set-key [C-drag-n-drop] 'ns-drag-n-drop-other-frame)
> (global-set-key [M-s-drag-n-drop] 'ns-drag-n-drop-as-text)
> (global-set-key [C-M-s-drag-n-drop] 'ns-drag-n-drop-as-text-other-frame)

Yes, but I was thinking of only changing this one

- (global-set-key [M-drag-n-drop] 'ns-drag-n-drop-as-text)
+ (global-set-key [M-s-drag-n-drop] 'ns-drag-n-drop-as-text)

as it's the only one unbound by default. This would be the bare minimum
change to make sure all unmodified dnd operations work by default. 

> BTW, is it just me or does ‘ns-drag-n-drop-as-text-other-frame’ not
> actually do anything different from ‘ns-drag-n-drop-as-text’?

The former pops up a new frame for me, but I have to bind it to an event
first. I don't think there's an easy way to generate the default
[C-M-drag-n-drop] event because of the way the modifiers are
interpreted, so `ns-drag-n-drop-as-text-other-frame' is never called.

> The current binding works if I drag and drop text from iterm2, but
> fails if I drag from textedit.

I'm guessing, but this might be expected. The sender sets the initial
operation mask based on its capabilities. I don't know iTerm2 very well,
but it probably doesn't support move operations (as its text is read
only) so it masks out the move to force a copy. Emacs receives
[drag-n-drop] and the op works because `ns-drag-n-drop' is smart enough
to know what to do with text on the pb. TextEdit supports both move and
copy, so it doesn't mask out the move, and Emacs receives
[M-s-drag-n-drop] which is currently unbound.