Skip to content

Conversation

@SimonSiefke
Copy link
Contributor

fixes #130036

For testing:

  1. Copy a file or folder
  2. Paste the file or folder into the VSCode files explorer using ctrl+v (or cmd+V on macOS)
  3. Verify the file or folder has been added to the VSCode files explorer

@lramos15 lramos15 requested review from bpasero and mjbvz and removed request for bpasero October 16, 2023 21:26
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool, does this run on all platforms?

@SimonSiefke
Copy link
Contributor Author

SimonSiefke commented Oct 18, 2023

Pretty cool, does this run on all platforms?

Thanks! I have only tested on Linux so far, but I can test on Windows tomorrow. I don't have any MacOs for testing.

Edit: On Windows it seems to work great as well!

@bpasero
Copy link
Member

bpasero commented Oct 19, 2023

I am also curious how this (if at all) interferes with VS Code internal copy/paste. For example, today you can copy a folder in one VS Code window and paste it into the explorer of another window and it works.

@SimonSiefke
Copy link
Contributor Author

In both cases the pasteFileHandler is called twice. Here are some examples:


Copying a folder in one VS Code window and pasting it into the vscode file explorer of another window

  1. keydown event fires
  2. KeyBinding is resolved: "^explorer.pasteFiles"
  3. Command "explorer.pasteFiles" is executed - the files are pasted here (using clipBoardService.readResources, reading "code/file-list" items from the clipboard)
  4. Due to the caret "^", event.preventDefault is not called
  5. Window paste event fires
  6. Command "explorer.pasteFiles" is executed again, this time with a FileList as argument - nothing happens since FileList is empty

Copying a folder from the native file explorer and pasting into the vscode file explorer

  1. keydown event fires
  2. KeyBinding is resolved: "^explorer.pasteFiles"
  3. Command is executed "explorer.pasteFiles" - nothing happens since there are no "code/file-list" items pasted
  4. Due to the caret "^", event.preventDefault is not called
  5. window paste event fires
  6. Command "explorer.pasteFiles" is executed again, this time with a FileList as argument - the files from the FileList are pasted here


Depending on the data, either "code/file-list" clipboard items or the paths from the FileList will be inserted.

So far in my testing, there have never been any conflicts/interferences between the two.

@bpasero bpasero requested review from bpasero and removed request for mjbvz October 29, 2023 07:43
@bpasero bpasero removed their assignment Oct 29, 2023
bpasero
bpasero previously approved these changes Oct 29, 2023
Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change LGTM, though I did not test it on Windows or Linux.

I wonder if we should show a dialog before pasting native files, simply because users might not be aware yet and its quite easy to accidentally paste and thus create a very large folder structure in the workspace if you happen to have one in the clipboard. The dialog could be tied to a new setting and have a checkbox to never ask again, similar to how we have that for preventing accidental drag and drop operations:

image

@vscodenpa vscodenpa added this to the October 2023 milestone Oct 29, 2023
@bpasero bpasero removed this from the October 2023 milestone Oct 29, 2023
lszomoru
lszomoru previously approved these changes Oct 29, 2023
@SimonSiefke
Copy link
Contributor Author

SimonSiefke commented Nov 2, 2023

While I totally get the potential pitfalls of accidental large pastes, adding a dialog might introduce an extra step that could disrupt the user flow. It seems to me much more rare to accidentally paste files with ctrl+v, that perhaps a dialog might not be necessary.

On the other hand, if multiple people report it as an issue, of course I would not be opposed to adding a dialog.

Perhaps we could merge this and gather some feedback from vscode-insiders users if there are any issues. What do you think?

@lramos15
Copy link
Member

lramos15 commented Nov 2, 2023

While I totally get the potential pitfalls of accidental large pastes, adding a dialog might introduce an extra step that could disrupt the user flow. It seems to me much more rare to accidentally paste files with ctrl+v, that perhaps a dialog might not be necessary.

I do wonder how much rarer that is though. I accidentally paste text all the time that I didn't mean to because I don't know what the contents of my clipboard are. It's also probably beneficial to align the experiences so moving and creating sets of files is all the same.

@lramos15 lramos15 added this to the November 2023 milestone Nov 2, 2023
@bpasero
Copy link
Member

bpasero commented Nov 2, 2023

Just to clarify: the dialog has a checkbox to never ask again (updating a setting). So its really up to the user. And its a nice gesture for users that are not aware of this change in the future.

@SimonSiefke
Copy link
Contributor Author

Okay, you have convinced me. I also wanted to avoid the extra work... :)

@SimonSiefke SimonSiefke dismissed stale reviews from lszomoru and bpasero via 5be58cc November 2, 2023 19:50
@SimonSiefke
Copy link
Contributor Author

Here is the paste file handler with the confirmation dialog:

paste.mp4

@lramos15
Copy link
Member

lramos15 commented Nov 2, 2023

image

Nit: These are folders not files

@lramos15 lramos15 merged commit 96b1781 into microsoft:main Nov 3, 2023
@lramos15
Copy link
Member

lramos15 commented Nov 3, 2023

Thanks so much for the contribution @SimonSiefke! This will be in Monday's insiders release for everyone to try :)

Copy link

@baldbull69 baldbull69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__

@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2023
@SimonSiefke SimonSiefke deleted the simon/explorer-paste branch January 15, 2026 16:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explorer: allow to paste files from the clipboard into target folder

8 participants