Uh oh!
There was an error while loading. Please reload this page.
Support Drag and Drop of Folders as well as files, fixes #668 - #659
Conversation
Your build failed around the eslint:src section.. my PR also failed around that sort of thing. How do we fix that?? |
humphd
commented
Mar 23, 2017
@Blackweda you just have to fix the lint errors. My code has some, it seems. I'll fix and push a patch. You can test it locally first to make sure lint passes. |
humphd
commented
Mar 25, 2017
I also added another commit that fixes https://github.com/mozilla/thimble.mozilla.org/issues/1886, allowing you to drag files/folders onto an existing dir vs. always importing to the project root. My code also auto-opens subdirs as you hover over them, in case they are closed. |
humphd
commented
Mar 25, 2017
@Pomax this PR is mostly dedicated to you. I should get you to test it and see if it works well for your use cases. Some things to try/note:
I don't have access to Windows and IE/Edge, so I don't know what it does in these browsers. But on Mac, it's working in Safari, Chrome, Firefox, and Opera. I'm fairly confident that I can do 2 more patches to follow this that will support:
I've now gotten the hang of the filetree code :) |
Pomax
commented
Mar 27, 2017
I tried this with a folder on my desktop called "test" containing |
Pomax
commented
Mar 27, 2017
Edge 14 does not like folder drag-and-drop, it would appear. I can't drop a folder onto the filetree in it. |
Pomax
commented
Mar 27, 2017
do we filter on extension @humphd? if I rename my |
humphd
commented
Mar 27, 2017
That Folder drag and drop is not going to work in IE/Edge (yet), no, so that's known. Dragging a bunch of files should work, though, in all browsers. |
Pomax
commented
Mar 27, 2017
barring that weird extension filtering, this actually seems to work pretty well. I tried dragging the folder into itself a few times. Works pretty well too - does highlight a question though: do we want a file-overwrite warning when a drop operation will overwrite existing files? |
Pomax
commented
Mar 28, 2017
if the overwrite issue is known and we have issues outstanding, then this is R+ from me. |
humphd
commented
Mar 29, 2017
Thanks for the reviews. I'm going to wait on a few other PRs to land that touch this code, and then I'll circle back, rebase, and try to get this in. |
… dropping deep into the filetree.
humphd
commented
May 8, 2017
@gideonthomas I've rebased this, and fixed a few things I noticed in testing. Do you want to take a look before I land? |
gideonthomas
commented
May 8, 2017
sure |
gideonthomas
left a comment
There was a problem hiding this comment.
Mainly just nits in the code!
I tested this out and it works well! One thing I noticed was that in Thimble, while dnd'ing folders/files/archives works perfectly if you do it directly even if there is a file in the folder that exceeds that max file size limit. However, if we use the "Upload Files" dialog and drag a folder (or archive or just the file) containing a file that is more than the max file size, it shows the error and then the editor just hangs. I feel like that is a known issue, but I'm not sure. If not, let's file a follow-up to fix in Thimble since we need to fix the strings in the "Upload Files" dialog as well (since we can upload folders now too)
| }); | ||
| }; | ||
| exports.create = function(byteLimit) { |
There was a problem hiding this comment.
rename to options since it's not just byteLimit?
| } | ||
| }; | ||
| exports.create = function(byteLimit) { |
| onMouseDown: this.handleMouseDown, | ||
| onDoubleClick: this.handleDoubleClick | ||
| onDoubleClick: this.handleDoubleClick, | ||
| onDragEnter: this.handleDragEnter |
There was a problem hiding this comment.
it's interesting that we don't need to bind to this here even though we use this inside handleDragEnter. Maybe it does .call(this, ...)?
| var files = event.dataTransfer.files; | ||
| var types = event.dataTransfer.types; | ||
| if ((!files || !files.length) && types) { // We only want to check if a string of text was dragged into the editor |
There was a problem hiding this comment.
if( !(files && files.length) && types )
I saw this tweet yesterday about CodePen's ability to let you drag and drop folders as well as files:
https://twitter.com/CodePen/status/843908650997600256?s=03
When I wrote our drag and drop stuff, browsers only supported files. So I did some research, and sure enough, Edge, Chrome, and Firefox all support it (hilariously, all via a
webkit*prefix method). The drag and drop and file api specs are a bit of a dog's breakfast, however, I was able to make it all work.With this patch, I've reworked our code to support both the new
webkitway (which supports folders and files) and also the old way, which only works with folders. Both ways still support auto-expanding of.zipand.tarfiles contained within.I could use some help really testing this on various browsers and files/folders. cc @Pomax and @flukeout.