-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from 1 commit
4f2828f
39b7592
3087701
9d2b9c6
16873fa
12c02d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,9 @@ export class Preview implements Disposable { | |
this.subprocess?.stdin?.write(`key ${direction} ${keyCode}\n`); | ||
} | ||
|
||
public async sendPaste(text: string) { | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what options do we have in regard to other protocols? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
this.subprocess?.stdin?.write(`paste ${text.replace(/(?:\r\n|\r|\n)/g, " ")}\n`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,19 +347,24 @@ function Preview({ | |
}, []); | ||
|
||
useEffect(() => { | ||
function dispatchPaste(e: ClipboardEvent) { | ||
function synchronizeClipboard(e: ClipboardEvent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.movI 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a toast notification for copy/paste copypaste.mov |
||
if (document.activeElement === wrapperDivRef.current) { | ||
e.preventDefault(); | ||
|
||
const text = e.clipboardData?.getData("text"); | ||
if (text) { | ||
project.dispatchPaste(text); | ||
} else { | ||
project.dispatchCopy(); | ||
} | ||
} | ||
} | ||
addEventListener("paste", dispatchPaste); | ||
|
||
addEventListener("paste", synchronizeClipboard); | ||
addEventListener("copy", synchronizeClipboard); | ||
return () => { | ||
removeEventListener("paste", dispatchPaste); | ||
removeEventListener("paste", synchronizeClipboard); | ||
removeEventListener("copy", synchronizeClipboard); | ||
}; | ||
}, [project]); | ||
|
||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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