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

Add bidirectional clipboard for iOS Simulator, support multiline paste, show toast when copying/pasting #936

Merged
merged 6 commits into from
Feb 12, 2025

Conversation

balins
Copy link
Contributor

@balins balins commented Feb 6, 2025

This PR introduces bidirectional clipboard support for iOS Simulator. The copying behaviour is similar to how cmd+v works, but instead of transferring hosts' clipboard content to the simulator, cmd+c transfers the simulator's clipboard to host's.

Apart from that, this PR prevents typing 'c' and 'v' when holding cmd and fixes multiline pastes (previously, newlines were recognized as starting separate commands, resulting in unrecognized command errors from simserver). It also adds a toast notifying user when copying/pasting is performed.

copypaste.mov

Fixes #160, #701

How Has This Been Tested:

Verified that:

  • command+C copies the Simulator's clipboard content to host
  • command+V pastes the host's clipboard content to the Simulator
  • command+C is ignored for Android Emulator (it automatically sends its clipboard to host whenever text is copied)
  • command+V pastes the hosts' clipboard content to Android Emulator's clipboard
  • typing 'c' and 'v' into Simulator/Emulator is prevented when holding 'command'
  • multiline paste works properly
  • toast is shown on cmd+c, cmd+v

@balins balins self-assigned this Feb 6, 2025
Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
radon-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 9:27am

Copy link
Collaborator

@filip131311 filip131311 left a comment

Choose a reason for hiding this comment

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

I left some comments

// ignore sending C and V when meta key is pressed
} else {
this.preview?.sendKey(keyCode, direction);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why, did you move this code to deviceBase I understand that is does not break android, as you pointed out in your comment, but it is still an ios specific workaround is it not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually applies to Android as well, otherwise it result in typing 'ccccc' or 'vvvvv' when trying to copy/paste to Android. And since it is a workaround for iOS and Android problems as well, I've elevated it higher

this.subprocess?.stdin?.write(`paste ${text}\n`);
public sendClipboard(text: string) {
// This is bad, but prevents simulator server going crazy with multiline pastes
// If we want to support multiline pastes we need to change the communication protocol
Copy link
Collaborator

Choose a reason for hiding this comment

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

what options do we have in regard to other protocols?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can either switch protocol completely, like move to GRPC or stay with communication via stdin-stdout, but add some markers for multiline commands, like this:

paste >>>STARTSIMSERVERPASTEhere is the
actual
multiline content
pasted by
the user<<<ENDSIMSERVERPASTE 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened a PR in simulator-server to handle this properly software-mansion-labs/simulator-server#222

@@ -347,19 +347,24 @@ function Preview({
}, []);

useEffect(() => {
function dispatchPaste(e: ClipboardEvent) {
function synchronizeClipboard(e: ClipboardEvent) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should inform user somehow that thay recived a clipboard?

Like in the example video:

Screen.Recording.2025-02-10.at.09.40.52.mov

I know that usually cmd+c does not trigger such a microinteraction, but this is a very specific case in witch user does not copy highlithed text but rather the contents of a clipboard on a simulated device.

Copy link
Collaborator

Choose a reason for hiding this comment

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

PS. I don't necessary think it needs to be part of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me, a small modal "device clipboard copied to host"/"host clipboard pasted to device" appearing on copy/paste would be sufficient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a toast notification for copy/paste

copypaste.mov

Copy link
Collaborator

@filip131311 filip131311 left a comment

Choose a reason for hiding this comment

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

I left an inline comment, but i am okay with the rest,
thank you

@@ -252,8 +260,31 @@ export class Project

//#endregion

async showToast(message: string, timeout: number) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be either part of UtilsInterface or just an utill imported here

@balins balins changed the title Add bidirectional clipboard support for iOS Simulator Add bidirectional clipboard for iOS Simulator, support multiline paste, show toast when copying/pasting Feb 12, 2025
@balins balins merged commit b039298 into main Feb 12, 2025
4 checks passed
@balins balins deleted the jb/bidirectional-clipboard branch February 12, 2025 09:29
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

Successfully merging this pull request may close these issues.

cannot copy to clipboard from simulator
2 participants