Feature Request - Copy with newline #2243

Closed
opened 2026-01-30 22:50:26 +00:00 by claunia · 3 comments
Owner

Originally created by @philippeller on GitHub (Jun 25, 2019).

Originally assigned to: @carlos-zamora on GitHub.

Summary of the new feature/enhancement

As had been an issue with later versions of the WSL terminal, also in the new windows terminal selecting and copying multiple lines does not preserve newline characters, but instead is filled up with trailing whitespace to match the terminal width.

Proposed technical implementation details (optional)

Separate lines should result in clipboard text with newlines, wrapped lines without.

Example

Copying some output from the terminal and pasting here:

Expected behavior:

$ ll /usr/lib
total 206M
lrwxrwxrwx   1 root root   23 Oct  8  2012 libqimageblitz.so.4 -> libqimageblitz.so.4.0.0
-rw-r--r--   1 root root  99K Oct  8  2012 libqimageblitz.so.4.0.0
-rw-r--r--   1 root root 6.0K Feb  2  2013 libporttime.so.0.0.0
lrwxrwxrwx   1 root root   20 Feb  2  2013 libporttime.so.0 -> libporttime.so.0.0.0
-rw-r--r--   1 root root  36K Feb  2  2013 libportmidi.so.0.0.0
lrwxrwxrwx   1 root root   20 Feb  2  2013 libportmidi.so.0 -> libportmidi.so.0.0.0
lrwxrwxrwx   1 root root   20 Jan  4  2014 libmsgpackc.so.2 -> libmsgpackc.so.2.0.0
-rw-r--r--   1 root root  23K Jan  4  2014 libmsgpackc.so.2.0.0
lrwxrwxrwx   1 root root   15 Feb 28  2014 libfam.so.0 -> libfam.so.0.0.0
-rw-r--r--   1 root root  35K Feb 28  2014 libfam.so.0.0.0
...

Actual behavior:

$ ll /usr/lib                                                                                                              total 206M                                                                                                                                lrwxrwxrwx   1 root root   23 Oct  8  2012 libqimageblitz.so.4 -> libqimageblitz.so.4.0.0                                                 -rw-r--r--   1 root root  99K Oct  8  2012 libqimageblitz.so.4.0.0                                                                        -rw-r--r--   1 root root 6.0K Feb  2  2013 libporttime.so.0.0.0                                                                           lrwxrwxrwx   1 root root   20 Feb  2  2013 libporttime.so.0 -> libporttime.so.0.0.0                                                       -rw-r--r--   1 root root  36K Feb  2  2013 libportmidi.so.0.0.0                                                                           lrwxrwxrwx   1 root root   20 Feb  2  2013 libportmidi.so.0 -> libportmidi.so.0.0.0                                                       lrwxrwxrwx   1 root root   20 Jan  4  2014 libmsgpackc.so.2 -> libmsgpackc.so.2.0.0                                                       -rw-r--r--   1 root root  23K Jan  4  2014 libmsgpackc.so.2.0.0                                                                           lrwxrwxrwx   1 root root   15 Feb 28  2014 libfam.so.0 -> libfam.so.0.0.0                                                                 -rw-r--r--   1 root root  35K Feb 28  2014 libfam.so.0.0.0                                                                                
Originally created by @philippeller on GitHub (Jun 25, 2019). Originally assigned to: @carlos-zamora on GitHub. # Summary of the new feature/enhancement <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> As had been an issue with later versions of the WSL terminal, also in the new windows terminal selecting and copying multiple lines does not preserve newline characters, but instead is filled up with trailing whitespace to match the terminal width. # Proposed technical implementation details (optional) <!-- A clear and concise description of what you want to happen. --> Separate lines should result in clipboard text _with_ newlines, wrapped lines without. # Example Copying some output from the terminal and pasting here: Expected behavior: ``` $ ll /usr/lib total 206M lrwxrwxrwx 1 root root 23 Oct 8 2012 libqimageblitz.so.4 -> libqimageblitz.so.4.0.0 -rw-r--r-- 1 root root 99K Oct 8 2012 libqimageblitz.so.4.0.0 -rw-r--r-- 1 root root 6.0K Feb 2 2013 libporttime.so.0.0.0 lrwxrwxrwx 1 root root 20 Feb 2 2013 libporttime.so.0 -> libporttime.so.0.0.0 -rw-r--r-- 1 root root 36K Feb 2 2013 libportmidi.so.0.0.0 lrwxrwxrwx 1 root root 20 Feb 2 2013 libportmidi.so.0 -> libportmidi.so.0.0.0 lrwxrwxrwx 1 root root 20 Jan 4 2014 libmsgpackc.so.2 -> libmsgpackc.so.2.0.0 -rw-r--r-- 1 root root 23K Jan 4 2014 libmsgpackc.so.2.0.0 lrwxrwxrwx 1 root root 15 Feb 28 2014 libfam.so.0 -> libfam.so.0.0.0 -rw-r--r-- 1 root root 35K Feb 28 2014 libfam.so.0.0.0 ... ``` Actual behavior: ``` $ ll /usr/lib total 206M lrwxrwxrwx 1 root root 23 Oct 8 2012 libqimageblitz.so.4 -> libqimageblitz.so.4.0.0 -rw-r--r-- 1 root root 99K Oct 8 2012 libqimageblitz.so.4.0.0 -rw-r--r-- 1 root root 6.0K Feb 2 2013 libporttime.so.0.0.0 lrwxrwxrwx 1 root root 20 Feb 2 2013 libporttime.so.0 -> libporttime.so.0.0.0 -rw-r--r-- 1 root root 36K Feb 2 2013 libportmidi.so.0.0.0 lrwxrwxrwx 1 root root 20 Feb 2 2013 libportmidi.so.0 -> libportmidi.so.0.0.0 lrwxrwxrwx 1 root root 20 Jan 4 2014 libmsgpackc.so.2 -> libmsgpackc.so.2.0.0 -rw-r--r-- 1 root root 23K Jan 4 2014 libmsgpackc.so.2.0.0 lrwxrwxrwx 1 root root 15 Feb 28 2014 libfam.so.0 -> libfam.so.0.0.0 -rw-r--r-- 1 root root 35K Feb 28 2014 libfam.so.0.0.0 ```
claunia added the Issue-BugArea-InteractionResolution-DuplicateProduct-Terminal labels 2026-01-30 22:50:26 +00:00
Author
Owner

@carlos-zamora commented on GitHub (Jun 26, 2019):

Wow. This is weird. Turns out this is a bug. Here's a repro:

  1. Open a Windows Terminal instance (trust me, close the one you have and open a new one)
  2. dir (or ls)
  3. make a selection of multiple lines
  4. right click to copy
  5. paste to notepad
  6. (this is where things get weird) THIS PASTE SHOULD BE FINE
  7. cls (or clear)
  8. repeat steps 2 - 5
  9. THIS PASTE SHOULD BE A MIX OF NEW SAME LINE AND NEW LINE TEXT

I did a bit of investigating. If you set a breakpoint on TermControl::CopySelectionToClipboard()s _terminal->ClearSelection();, use a debugger to take a look at the contents of copiedData.

On step 4 (both times you do it), you should hit this breakpoint. copiedData is different both times. I guess the problem is in Terminal::RetrieveSelectedTextFromBuffer()

@carlos-zamora commented on GitHub (Jun 26, 2019): Wow. This is weird. Turns out this is a bug. Here's a repro: 1. Open a Windows Terminal instance (trust me, close the one you have and open a new one) 2. `dir` (or `ls`) 3. make a selection of multiple lines 4. right click to copy 5. paste to notepad 6. (this is where things get weird) THIS PASTE SHOULD BE FINE 7. `cls` (or `clear`) 8. repeat steps 2 - 5 9. THIS PASTE SHOULD BE A MIX OF NEW SAME LINE AND NEW LINE TEXT I did a bit of investigating. If you set a breakpoint on `TermControl::CopySelectionToClipboard()`s `_terminal->ClearSelection();`, use a debugger to take a look at the contents of `copiedData`. On step 4 (both times you do it), you should hit this breakpoint. `copiedData` is different both times. I guess the problem is in `Terminal::RetrieveSelectedTextFromBuffer()`
Author
Owner

@carlos-zamora commented on GitHub (Jun 26, 2019):

Assigning myself but happy if anybody wants to take it off my plate since I won't get to it for a while :)

@carlos-zamora commented on GitHub (Jun 26, 2019): Assigning myself but happy if anybody wants to take it off my plate since I won't get to it for a while :)
Author
Owner

@DHowett-MSFT commented on GitHub (Jun 27, 2019):

Isn't this a duplicate of #1073?

@DHowett-MSFT commented on GitHub (Jun 27, 2019): Isn't this a duplicate of #1073?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2243