Repository navigation
Fix Copy Path pasteboard contents so the path can be pasted into Terminal - #879
Open
monsterlag wants to merge 1 commit into
Open
monsterlag wants to merge 1 commit into
monsterlag wants to merge 1 commit into
Conversation
…inal Copy Path declared a URL type without providing data and then appended a second pasteboard item, so apps reading the first item (Terminal, Pasteboard Viewer) found nothing to paste. Write one item carrying both the plain-text path and the file URL. Fixes XcodesOrg#824
This branch has not been deployed
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.
Note
AI-generated, not reviewed by a human. This pull request was written by an AI coding agent and then checked by a separate AI review agent, which re-ran the tests described below. No human has reviewed the code. It is submitted by @monsterlag, who runs these agents. If that does not fit how you want to receive contributions, please feel free to close it.
Fixes #824
What was wrong
AppState.copyPath(xcode:)calleddeclareTypes([.URL, .string], owner: nil), thenwriteObjects([url as NSURL]), thensetString(_:forType: .string). That leaves two pasteboard items:public.url,public.utf8-plain-textpublic.urlis declared but never provided (nil); the text is the pathpublic.file-urlfile:///Applications/Xcode%2026.0.apppbpastestill finds the plain text, but apps that read the first item's URL type find no data. That matches the report: Terminal and Pasteboard Viewer paste nothing.How it is fixed
copyPathnow clears the pasteboard and writes a singleNSPasteboardItemthat carries both the plain-text path (.string) and the file URL (.fileURL). Both types have real data. It also takes an optionalpasteboardparameter, defaulting to.general, so a test can use a private pasteboard.copyReleaseNote(from:)writes the pasteboard in the same way and may have the same problem. I left it alone to keep this change scoped to the issue.How it was tested
The tests ran on macOS 26.6 with Xcode 27.1:
AppStateTests.test_CopyPath_WritesOneItemWithPathAndFileURLuses a uniquely namedNSPasteboard. It checks for exactly one item that holds the path and the file URL, using an app path that contains a space.xcodebuild test -scheme Xcodes -destination "platform=macOS" -only-testing:XcodesTests/AppStateTestsfailed only the new test, with 3 assertion failures. The item count was 2, the first item's types werepublic.url, public.utf8-plain-text, and the file URL was nil.xcodebuild test -scheme Xcodes -destination "platform=macOS"(the CI command) passed:Executed 52 tests, with 0 failures,** TEST SUCCEEDED **.Pasting was checked in a macOS 26.6 desktop session (Cmd+V sent through System Events): with the old code Terminal pastes nothing, which reproduces the issue; with the fix Terminal pastes the shell-escaped path (
/Users/admin/pbtest/Xcode\ 26.0.app, the same as dropping the file), andpbpastegives the plain path.One behaviour change: rich-text TextEdit now inserts a file attachment instead of the path text. The new layout is the same one Finder's own Copy as Pathname (Option-Command-C) writes on macOS 26.6 (one item with
public.file-urlandpublic.utf8-plain-text). If you'd rather have plain text everywhere, a single item with.URLplus.stringalso fixes the issue (Terminal and TextEdit then both get the unescaped path); happy to switch to that.