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

Clipboard: handle multiple CR+LF #1845

Merged
merged 1 commit into from
Mar 26, 2024
Merged

Clipboard: handle multiple CR+LF #1845

merged 1 commit into from
Mar 26, 2024

Conversation

syrykh
Copy link

@syrykh syrykh commented Mar 25, 2024

In case copied from the remote server text contains multiple new-lines, only the first occurence of "\r\n" is properly replaced with '\n'. If the received text is then directly written to clipboard with navigator.clipboard.writeText(e.detail.text), empty lines will be duplicated on macOS.

image

This PR addresses this issue by replacing all the occurrences instead.

Copy link
Member

@CendioOssman CendioOssman left a comment

Choose a reason for hiding this comment

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

Thanks! That's a bit embarrassing that it was overlooked. :)

@CendioOssman CendioOssman merged commit 9a1b1f0 into novnc:master Mar 26, 2024
11 checks passed
@samhed samhed added this to the v1.5.0 milestone Mar 28, 2024
@samhed
Copy link
Member

samhed commented Mar 28, 2024

Thank you for the fix.

Out of interest, I attempted — and failed — to see the practical effects of this. You mentioned “empty lines will be duplicated on macOS”, what are the steps for this to happen?

What I did:

On the remote (RHEL 9 with MATE), I created a text file with \r\n linebreaks:

echo -ne "1\r\n" >> myfile
echo -ne "2\r\n" >> myfile
echo -ne "3" >> myfile

I then connected using noVNC from Safari on macOS. I opened myfile in both Pluma and vim and both apps displayed the file as containing 3 rows as expected. After copying the contents I still see it as 3 rows, both in the clipboard textarea in Safari, and in macOS notes when pasted.

Note that I can verify, using Safari's developer tools, that I see the bug. The textData in my JavaScript event contains 1\n2\r\n3.

@syrykh
Copy link
Author

syrykh commented Mar 28, 2024

Hi @samhed,

It seems that most of macOS apps convert "\r\n" to "\n" on the fly, so it's hard to spot. You can try Alacritty terminal emulator, where this issue is visible: if you do echo -e '1\n2\r\n3' | pbcopy in a standard terminal, then open vim in the alacritty and paste, you'll see this:
Screenshot 2024-03-28 at 17 36 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants