New lines when copy/paste from guest ubuntu

Discussions about using Linux guests in VirtualBox.
Post Reply
Ian_
Posts: 3
Joined: 23. Aug 2022, 13:52

New lines when copy/paste from guest ubuntu

Post by Ian_ »

Hi all!

I've spent all morning googling and searching on here but I cannot find anything recent that matches my problem. I'm running virtualbox and Ubuntu 22_04. I updated from Ubuntu 20_xx and then updated virtualbox additions but found that copying text from the ubuntu guest and pasting to the windows host would add an extra line. I've tried updating VBox & reinstalling VBoxAdditions but I'm still hitting this problem.

To demonstrate. I copied this text (r-mouse, copy)

This
is
a
test

If I paste into vi from ubuntu and cat -e, then I get this..

This$
is$
a$
test$
$

Which is nice but when I paste the same into the host windows notepad and cat -e that, I get this..

This^M$
is^M$
a^M$
test^M$
^M$

I'm sure I'm not alone hitting this problem. Copy & paste between the 2 worked fine until I updated to the latest Ubuntu. Somewhere, the carriage return linefeed is being misinterprated between ubuntu & virtualbox..?

Any thoughts?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: New lines when copy/paste from guest ubuntu

Post by mpack »

Obviously this must be due to the difference in text line endings between Unix/Linux and Dos/Windows cultures. Unix uses LF only, DOS/Win uses CR,LF (^M, ^J). I suspect the outcome will depend very much on what you paste the text clipping into.
Ian_
Posts: 3
Joined: 23. Aug 2022, 13:52

Re: New lines when copy/paste from guest ubuntu

Post by Ian_ »

Indeed. That's the conclusion I came to but I don't understand why an ubuntu update would cause this. I can only think that there's a bug or feature within the current virtualbox additions. I found copying & pasting between the 2 machines really handy and would hate to loose this.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: New lines when copy/paste from guest ubuntu

Post by fth0 »

Ubuntu 20.04 defaults to X11. Ubuntu 22.04 defaults to Wayland. If you boot Ubuntu 22.04 with X11, does the issue persist?
Ian_
Posts: 3
Joined: 23. Aug 2022, 13:52

Re: New lines when copy/paste from guest ubuntu

Post by Ian_ »

Amazing! Yes, switching to "Ubuntu on Xorg" on the logon screen fixed it. Thank you so much!
I.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: New lines when copy/paste from guest ubuntu

Post by mpack »

That puzzles me. I didn't suggest the Wayland idea because I expected that the clipboard would either work or not work, I did not expect that on Wayland it would work but with a different behaviour. I don't see why the mechanics of how you put stuff on a clipboard should change what you put there... unless this line ending conversion function (strip CRs?) was a feature of the x11 clipboard, not a feature of VirtualBox?
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: New lines when copy/paste from guest ubuntu

Post by fth0 »

mpack wrote:I expected that the clipboard would either work or not work, I did not expect that on Wayland it would work but with a different behaviour.
On one hand, the VirtualBox developers would tell you that the Wayland clipboard is not supported, and that they don't know any differences between the X11 compatible XWayland clipboard and the X11 clipboard. On the other hand, I know quite a bit about the complexity of clipboard infrastructures (*), so I wanted to get the "Wayland vs. XWayland vs. X11" aspect out of the way first.

(*) As a very primitive measure of the complexity, try to find another VirtualBox component that was more often fixed during the VirtualBox 6.1.x release updates than ten times. ;)
mpack wrote:I don't see why the mechanics of how you put stuff on a clipboard should change what you put there... unless this line ending conversion function (strip CRs?) was a feature of the x11 clipboard, not a feature of VirtualBox?
In general, the line-ending conversion could take place at a lot of places: The guests application, a guest's clipboard manager, the guest's clipboard, the VirtualBox clipboard implementation, the host's clipboard, a host's clipboard manager, and the host's application (e.g. Notepad). Each of the involved clipboard entities supports several types of clipboard contents, but not necessarily the same types, so those types are converted possibly multiple times.

And as if that wasn't complicated enough, in the original X11 clipboard implementation, the copying of clipboard contents only takes place at paste time, which is a challenge for implementing an inter-OS clipboard like the one in VirtualBox.

Regarding the OP's description, I'm not even sure which behavior was the expected one. On a Linux PC, vim displays Windows text file lines normally as "This^M".
himmel92
Posts: 1
Joined: 21. Nov 2019, 15:15

Re: New lines when copy/paste from guest ubuntu

Post by himmel92 »

This is a miracle - I've been trying to figure this out for over a year. I switched to "GNOME on Xorg" and the bi-directional clipboard is useful again!! Thanks!
Post Reply