Skip to content
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

not cross-platform? #2

Open
shin-ra opened this issue Jul 17, 2019 · 3 comments
Open

not cross-platform? #2

shin-ra opened this issue Jul 17, 2019 · 3 comments

Comments

@shin-ra
Copy link

shin-ra commented Jul 17, 2019

dragging and dropping a markdown file is not working on win 10, but doing the same with text files work.

@Ventrosky
Copy link

I found some issues too, maybe could be related @shin-ra :

  • One was with the macOS methods setDocumentEdited and isDocumentEdited undefined in Win using Electron 7 so I had to implement them. (not your case since .txt works for you)
  • Second issue was with the function fileTypeIsSupported, the property type of the dragged files shows an empty string, so I check the extension with a simple regexp in those cases.

check out this commit

@robertpatrick
Copy link

robertpatrick commented Feb 19, 2021

@Ventrosky the fileTypeIsSupported implementation in your commit works on MacOS for the drop event but not the dragover event where both file.type and file.name fields are both empty.

@Ventrosky
Copy link

Ventrosky commented Feb 19, 2021

oh my it has been so long :) here it's the bit of code referenced by @robertpatrick

const getDraggedFile = (event) => event.dataTransfer.items[0];
const getDroppedFile = (event) => event.dataTransfer.files[0];

// used in the handlers to add drag-over/ drag-error classes
const fileTypeIsSupported = (file) => {
    return file.type ?  
        ['text/plain', 'text/markdown'].includes(file.type)  : 
        /\.(md|markdown|txt)$/i.test(file.name);
};

It's interesting dho, because from the docs the DataTransferItem should contain the MIME type, didn't have problems with dragover on linux or win 10 when I tested it with files with the extension .md or .txt but didn't have the chance to try it on a mac.
While the regexp test on file.name makes sense only for the file elements returned by getDroppedFile used for handling the drop event.
Looking back I have some objections on how I wrote this function and I think those two checks should be separated. Something like this would have been much clearer of what I think where my intentions:

const supportedDragoverItem =  (item) => ['text/plain', 'text/markdown'].includes(item.type);
const supportedDropFile =  (file) => /\.(md|markdown|txt)$/i.test(file.name);

While this doesn't solve the dragover problem on a Mac maybe can still help with the investigation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants