Windows build number: Version 10.0.18362.239
Windows Terminal version: 0.3.2142.0
C:\>set path
Newlines to be copied
c:\project-system>set path
Path=C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\FSharp\;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Git\cmd;C:\Users\davkean\AppData\Local\Microsoft\WindowsApps;C:\Users\davkean\.dotnet\tools
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Newlines are thrown away:
c:\>set path Path=C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\FSharp\;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Git\cmd;C:\Users\davkean\AppData\Local\Microsoft\WindowsApps;C:\Users\davkean\.dotnet\tools PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
I've confirmed that @drewnoakes and @davidwengier can also reproduce this. Occasionally it will copy the newlines but have not been able to figure out logic.
These are my copy bindings, but I've confirmed if I remove copyTextWithoutNewlines the behavior above still occurs:
{
"command": "copy",
"keys": [
"ctrl+c"
]
},
{
"command": "copyTextWithoutNewlines",
"keys": [
"ctrl+shift+c"
]
},
Adding Help-Wanted, in case I can't get to it in time. #1093 is the PR that created these options, so that'll be a good idea of where to start looking.
I think I can reproduce this issue if i just open a cmd, hit enter a few times to generate a few lines new lines and then resize the window (shrink it into a small window). If I didn't resize the window then new lines were preserved but once everything had to reflow newlines don't get preserved anymore. Weird.
Turns out, the clipboard code is correct. ConHost uses the same clipboard code. The issue arises with the wrap property on the CharRows. Windows Terminal does not set them properly. Significantly more info below.
In the example above, say the output is displayed as follows (line numbers on left):
0 c:\project-system>set path
1 Path=C:\Program Files (x86)\Microsoft Visual Studio\2019\master\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Users\dav
2 kean\AppData\Local\Microsoft\WindowsApps;C:\Users\davkean\.dotnet\tools
3 PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
This means that the wrap is supposed to be...
| Line # | wrap? (ConHost) | wrap? (Windows Terminal) |
|-- |-- |-- |
| 0 | false | false |
| 1 | true | true |
| 2 | false | true |
| 3 | false | true |
@miniksa and I tried doing a proper fix in branch dev/cazamor/bugfix-copy-newline, but that caused more issues to arise. Specifically, take a look at line 2. In the VT Renderer, we called _EraseCharacter() to put spaces until the end of the line. We noticed that that would trigger the text buffer to set that line as "wrapping". The branch changes it to instead call _EraseLine(), which should be more efficient too.
We also updated the TerminalApi for Terminal Core to writeLine() instead of just Write() in Terminal::EraseInLine().
The result was the following:
| Line # | wrap? (dev/cazamor/bugfix-copy-newline) |
|-- |-- |
| 0 | false |
| 1 | false |
| 2 | false |
| 3 | false |
@miniksa was saying that this is a combined problem between the TerminalApi and the VTRenderer. May also be related to #780.
@zadjii-msft @miniksa Thoughts?
Removing the "Help-Wanted" tag because this is out of that scope now.
EDIT: I just tried reverting the change to the TerminalApi and this particular instance is fixed. Is that correct?
I confirm this incorrect and very annoying behavior, compare these two files: FromPS7p3RunningInWindowsTerminal.docx
FromStandardPS7p3Host.docx
:tada:This issue was addressed in #2797, which has now been successfully released as Windows Terminal Preview v0.5.2661.0.:tada:
Handy links:
hi, I'm using the version v0.5.2661.0 and I can confirm that the copy problem is resolved but when I try to paste multiple lines in the terminal (on vim, nano, etc...) one extra new line is added after every line.

It seems like this issue is not solved for me. When I select text, righ-click it and paste, it's all pasted as 'a single line'.. Version is 0.5.2681.0. Makes it very hard to use vim in a productive way..
Just to be sure: you're copying from Terminal, and pasting into Terminal?
I have this problem on version 0.5.2681.0, copying from Terminal (Pengwin), and pasting back into Terminal (vim) or VSCode. I haven't found a scenario where it does work correctly.
@sba923 Correct, copying from terminal wsl2 Ubuntu to same tab terminal wsl2 Ubuntu
Sometimes I can repro this, sometimes I can't.
I'm using bash in WSL 1 Ubuntu 18.04.
I'm generating 4 lines using:
echo -e "echo a\necho b\necho c\n"
From there, I select the 3 "echo" lines and copy them.
Then I paste them back.
Sometimes I get:

which is correct, sometimes I get this instead:

which is incorrect.
When I launch a new tab, the behavior is always correct.
If I use "clear" in bash to clear the terminal, the behavior is from there on always incorrect.
HTH
@Drugoy Do you have a reason why you'd like this reopened? This was presumably fixed almost a year ago, so if you're seeing something like this, then it's probably from an unrelated root cause that would deserve it's own investigation.
@zadjii-msft just realized this is a wrong repo to report. I use built-in (cmd.exe) terminal, not 'windows terminal'. But yeah, I have this issue.
Well, this is actually the repo for both the Windows Terminal and the vintage console (conhost.exe, the window you think of when you think of cmd.exe). I'd open a new issue, because this thread is definitely WT-specific.
Most helpful comment
hi, I'm using the version v0.5.2661.0 and I can confirm that the copy problem is resolved but when I try to paste multiple lines in the terminal (on vim, nano, etc...) one extra new line is added after every line.