Copy inconsistently copies as "copyTextWithoutNewlines" #3177

Closed
opened 2026-01-30 23:14:49 +00:00 by claunia · 15 comments
Owner

Originally created by @davkean on GitHub (Aug 6, 2019).

Environment

Windows build number: Version 10.0.18362.239
Windows Terminal version: 0.3.2142.0

Steps to reproduce

  1. Launch cmd and run following command:
C:\>set path
  1. Using mouse highlight from 1,1 -> end of the terminal
  2. Right-click (or CTRL+SHIFT+C) to copy text

Expected behavior

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 

Actual behavior

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.

Originally created by @davkean on GitHub (Aug 6, 2019). # Environment ```none Windows build number: Version 10.0.18362.239 Windows Terminal version: 0.3.2142.0 ``` # Steps to reproduce 1. Launch cmd and run following command: ``` C:\>set path ``` 2. Using mouse highlight from 1,1 -> end of the terminal 3. Right-click (or CTRL+SHIFT+C) to copy text # Expected behavior 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 ``` # Actual behavior 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.
claunia added the Issue-BugIn-PRArea-InteractionProduct-Terminal labels 2026-01-30 23:14:49 +00:00
Author
Owner

@davkean commented on GitHub (Aug 6, 2019):

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"
      ]
    },
@davkean commented on GitHub (Aug 6, 2019): 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" ] },
Author
Owner

@carlos-zamora commented on GitHub (Aug 7, 2019):

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.

@carlos-zamora commented on GitHub (Aug 7, 2019): 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.
Author
Owner

@sregister commented on GitHub (Aug 12, 2019):

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.

@sregister commented on GitHub (Aug 12, 2019): 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.
Author
Owner

@carlos-zamora commented on GitHub (Sep 17, 2019):

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?

@carlos-zamora commented on GitHub (Sep 17, 2019): 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?
Author
Owner

@sba923 commented on GitHub (Sep 19, 2019):

I confirm this incorrect and very annoying behavior, compare these two files: FromPS7p3RunningInWindowsTerminal.docx
FromStandardPS7p3Host.docx

@sba923 commented on GitHub (Sep 19, 2019): I confirm this incorrect and **very annoying** behavior, compare these two files: [FromPS7p3RunningInWindowsTerminal.docx](https://github.com/microsoft/terminal/files/3631772/FromPS7p3RunningInWindowsTerminal.docx) [FromStandardPS7p3Host.docx](https://github.com/microsoft/terminal/files/3631773/FromStandardPS7p3Host.docx)
Author
Owner

@ghost commented on GitHub (Sep 24, 2019):

:tada:This issue was addressed in #2797, which has now been successfully released as Windows Terminal Preview v0.5.2661.0.🎉

Handy links:

@ghost commented on GitHub (Sep 24, 2019): :tada:This issue was addressed in #2797, which has now been successfully released as `Windows Terminal Preview v0.5.2661.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.5.2661.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Author
Owner

@carlosrmendes commented on GitHub (Sep 25, 2019):

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.

image

@carlosrmendes commented on GitHub (Sep 25, 2019): 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. ![image](https://user-images.githubusercontent.com/7363029/65588439-70557480-df7f-11e9-8013-1f927e47aa2c.png)
Author
Owner

@willemdh commented on GitHub (Sep 30, 2019):

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..

@willemdh commented on GitHub (Sep 30, 2019): 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..
Author
Owner

@sba923 commented on GitHub (Sep 30, 2019):

Just to be sure: you're copying from Terminal, and pasting into Terminal?

@sba923 commented on GitHub (Sep 30, 2019): Just to be sure: you're copying from Terminal, and pasting into Terminal?
Author
Owner

@valorin commented on GitHub (Oct 1, 2019):

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.

@valorin commented on GitHub (Oct 1, 2019): 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.
Author
Owner

@willemdh commented on GitHub (Oct 1, 2019):

@sba923 Correct, copying from terminal wsl2 Ubuntu to same tab terminal wsl2 Ubuntu

@willemdh commented on GitHub (Oct 1, 2019): @sba923 Correct, copying from terminal wsl2 Ubuntu to same tab terminal wsl2 Ubuntu
Author
Owner

@sba923 commented on GitHub (Oct 3, 2019):

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:

image

which is correct, sometimes I get this instead:

image

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

@sba923 commented on GitHub (Oct 3, 2019): 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: ![image](https://user-images.githubusercontent.com/12860484/66098937-efacfe80-e5a4-11e9-805f-38df4ff471f9.png) which is correct, sometimes I get this instead: ![image](https://user-images.githubusercontent.com/12860484/66098965-018ea180-e5a5-11e9-9d73-b5c15041ac27.png) 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
Author
Owner

@zadjii-msft commented on GitHub (Aug 14, 2020):

@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 commented on GitHub (Aug 14, 2020): @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.
Author
Owner

@Drugoy commented on GitHub (Aug 14, 2020):

@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.

@Drugoy commented on GitHub (Aug 14, 2020): @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.
Author
Owner

@zadjii-msft commented on GitHub (Aug 14, 2020):

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.

@zadjii-msft commented on GitHub (Aug 14, 2020): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3177