-
Notifications
You must be signed in to change notification settings - Fork 29.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable macOS animation when drag operation cannot be completed #199635
Comments
👍 , would be great to upstream. I guess for Chrome to accept this eventually, it would have to be an opt-in thing to not break existing behaviour (thats just my assumption). Maybe this could be done on the level of the drag image APIs? For example, when you set a drag image with a |
Yup that is what I am going for in the Option 1), adding new webkit property on the data transfer object. Borrowed the idea from the firefox patch. |
If you are good with writing a W3C proposal and then going through the procedure to get it approved, then adding a Have you considered using the It is much easier adding an option for |
@zcbenz my understanding is that |
Yeah you are right the API is currently only for files, I forgot that. And this API lacks the ability to handle end of dragging. I'm mentioning The downside is, it will make drag and drop code much more complicated when all you need is just |
Note that the native module itself is easy to write if you only want to do this approach on macOS, the problem is your drag drop code's structure would become something like this: For Linux/Windows, just do drag and drop in DOM. I can write a demo of the native module if you decide to go this approach. |
Wow, thats an incredibly detailed blog post, very helpful, thanks for sharing! Thanks for your offer, but I think I would not want to go down the path of a native module, given our ability to disable this animation in our builds easily. However, there is still one issue on Windows that I am not yet sure if we can solve it: using drag and drop without data transfer means that Windows will signal back that dropping is not possible (showing a red icon). You can see that this is even an issue with Firefox today: I was not able to find a workaround using HTML APIs and I wonder if even with Windows it would be possible to trick Windows into believing the drop is possible, even when there is no transfer associated that the target can handle. My only idea for trying to fix this would be to open a little transparent window in the background that moves with the mouse cursor and always signals back that dropping is possible. However, I think that during drag and drop operations, we are not even getting the mouse position as events back, so it might be hard to get this right. |
In native code you can set the dataTransfer to a URL so the Also after testing with Chrome and Edge's tab dragging, I believe they are not using system drag drop, and Chromium's tab dragging code seems to confirm so: It should be possible to duplicate Chrome's tab dragging behavior with js code. When user drags a tab in DOM, don't use the HTML drag drop APIs, instead call |
I had thought about dropping our drag-and-drop solution for a mouse-event only solution but there are downsides: we do allow to drop a tab into an existing window of VS Code to have the tab open in there. For that we do set a data transfer that is specific to VS Code. I am not sure I could replicate this behaviour using mouse-events alone. But thanks for the pointer, I was not aware of that API yet 🙏 |
Chromiums implements tab dragging between existing windows by getting the window below the cursor when mouse is released: It does not do data transfer between windows, instead it handles mouse movements directly and operates on windows directly. Chromium's approach is really complicated and error-prone to implement in an Electron app since there is extra layer of inter process communication, but if you want a perfect tab dragging experience it is probably the practical way to go. It is not hard to add an Electron API to return the BrowserWindow under the cursor. |
With floating windows support in VSCode we now have scenarios to drag an editor tab outside the application without having to complete the drop on external applications. This leads to macOS performing the default slide animation to return the dragged image back to its source location as seen in the recording below,
Screen.Recording.2023-11-30.at.15.38.22.mov
This causes an undesirable delay before the new editor window gets created and we would like to avoid that if possible. I was looking around the
NSDraggingSession
documentation and found the following property animatesToStartingPositionsOnCancelOrFail would allow us to control the behavior. As a quick test, the following patch always disables the animation and the result looks much better,Screen.Recording.2023-11-30.at.15.48.03.mov
Interestingly, I found that firefox did a similar change earlier this year https://hg.mozilla.org/mozilla-central/rev/b2954fa754d2 that disables the animation for tabs dragged out of the window or if the drag operation has an empty data transfer object. I am now thinking how we can upstream this as a proper change to Chromium, in our case we cannot set an empty data transfer object since we need the data when dragging editors between windows of the application and also data transfer object can only be set on drag start and is immutable once set which does not give enough options for us to change the data based on drop destination. Options I can think of,
A new property on DataTransfer
event.dataTransfer.webkitShowFailAnimation
which applications can controlAlways disable the animation when drop is performed outside the application bounds ? Wondering if there are scenarios that could counter this.
/cc @zcbenz @bpasero
The text was updated successfully, but these errors were encountered: