File Shelf: keep a dragged-out file's name - #35
Merged
Conversation
NSItemProvider(contentsOf:) leaves suggestedName nil while registering the file's content type ahead of public.file-url, so a receiver taking the first representation it is offered got the bytes with no name attached and invented one. Verified with a probe: contentsOf: alone reports suggestedName nil and types [public.plain-text, public.file-url, public.url]. Naming the provider fixes it without narrowing what is on offer — a receiver that wants the URL and one that wants the contents both still get what they ask for, which is why this is not simply NSItemProvider(object: url as NSURL). Also returns nil for a file that has gone since the last resolve. The row is gated on availability, but that answer is as old as the last check, and contentsOf: hands back a provider either way — which would start a drag that delivers nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported from testing 0.16.0 on a real machine: a file dragged out of the shelf arrives at its destination without its name.
Cause
NSItemProvider(contentsOf:)leavessuggestedNamenil while registering the file's content type ahead ofpublic.file-url. A receiver that takes the representation it is offered first therefore gets bytes with nothing to call them, and names the result itself.Confirmed with a probe rather than inferred:
NSItemProvider(contentsOf:)— what shippednilpublic.plain-text,public.file-url,public.urlNSItemProvider(object: url as NSURL)nilpublic.file-url,public.urlcontentsOf:+suggestedNameQuarterly Report.txtpublic.plain-text,public.file-url,public.urlFix
FileShelfKit.dragProvider(for:)sets the suggested name and keeps every representation on offer. Deliberately notNSItemProvider(object: url as NSURL): that also fixes the name, but drops the content representation, so a receiver that wants the bytes rather than a path loses out.It also returns
nilfor a file that has gone since the last resolve. The row is gated onisAvailable, but that answer is as old as the last check andcontentsOf:returns a provider regardless — which starts a drag that delivers nothing. Found because a test I wrote assumed the opposite and failed.Tests
1182 → 1185. The name, that both representations survive, and that a vanished file yields no payload.
Ships in the next release; 0.16.0 has the bug.