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

Fix explorer paste #200601

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Fix explorer paste #200601

merged 1 commit into from
Dec 12, 2023

Conversation

lramos15
Copy link
Member

Fixes #200581

Seems like there was two issues here

  1. You cannot write both a resource and text to the clipboard at the same time
  2. Paste was being double triggered causing errors. We shouldn't trigger the native paste handler when no native files are present

cc @bpasero Is there anyway to do the first point?

It seems like reading resources returns nothing if I write text after writing a resource. My hope was that I could have both text and resources written and when pasting depending on the context the proper one would be read

async function getFilesToPaste(fileList: FileList | undefined, clipboardService: IClipboardService): Promise<readonly URI[]> {
if (fileList && fileList.length > 0) {
// with a `fileList` we support natively pasting files from clipboard
return [...fileList].filter(file => !!file.path && isAbsolute(file.path)).map(file => URI.file(file.path));
} else {
// otherwise we fallback to reading resources from our clipboard service
return resources.distinctParents(await clipboardService.readResources(), resource => resource);
}
}

@lramos15 lramos15 self-assigned this Dec 12, 2023
@lramos15 lramos15 enabled auto-merge (squash) December 12, 2023 01:30
@lramos15 lramos15 merged commit 72cb92f into main Dec 12, 2023
6 checks passed
@lramos15 lramos15 deleted the lramos15/organisational-mole branch December 12, 2023 01:44
@bpasero
Copy link
Member

bpasero commented Dec 12, 2023

@lramos15 please sync with @deepak1556 on that question, in the end we delegate directly to Electron APIs for writing:

return clipboard.writeText(text, type);

return clipboard.writeBuffer(format, Buffer.from(buffer.buffer), type);

@deepak1556
Copy link
Contributor

You cannot write both a resource and text to the clipboard at the same time

This is expected, each clipboard call is synchronous and there is only a single instance of the clipboard to the process. At a time a clipboard can contain multiple representations but not from different calls.

For your scenario, you need https://github.com/electron/electron/blob/main/docs/api/clipboard.md#clipboardwritedata-type but it does not support buffer. We can add support for that in upstream, but you can also switch to using the web clipboard api https://web.dev/articles/async-clipboard

@lramos15 lramos15 added this to the November 2023 Recovery 1 milestone Dec 12, 2023
lramos15 added a commit that referenced this pull request Dec 12, 2023
lramos15 added a commit that referenced this pull request Dec 12, 2023
Fix explorer paste (#200601)

Fix paste
@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2024
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.

Cannot copy/paste files anymore between folders
4 participants