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

Copy inconsistently copies as "copyTextWithoutNewlines" #2275

Closed
davkean opened this issue Aug 6, 2019 · 15 comments · Fixed by #2797
Closed

Copy inconsistently copies as "copyTextWithoutNewlines" #2275

davkean opened this issue Aug 6, 2019 · 15 comments · Fixed by #2797
Labels
Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Milestone

Comments

@davkean
Copy link
Member

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

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Aug 6, 2019
@davkean
Copy link
Member Author

davkean commented 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"
      ]
    },

@carlos-zamora carlos-zamora added Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Help Wanted We encourage anyone to jump in on these. and removed Needs-Tag-Fix Doesn't match tag requirements labels Aug 7, 2019
@carlos-zamora carlos-zamora added this to the Terminal 1908.1 milestone Aug 7, 2019
@carlos-zamora
Copy link
Member

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.

@sregister
Copy link

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.

@ghost ghost added In-PR This issue has a related PR and removed In-PR This issue has a related PR labels Sep 14, 2019
@carlos-zamora
Copy link
Member

carlos-zamora commented 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?

@ghost ghost added the In-PR This issue has a related PR label Sep 17, 2019
@carlos-zamora carlos-zamora removed the Help Wanted We encourage anyone to jump in on these. label Sep 17, 2019
@sba923
Copy link

sba923 commented Sep 19, 2019

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

@ghost
Copy link

ghost commented Sep 24, 2019

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

Handy links:

@carlosrmendes
Copy link

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

@willemdh
Copy link

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

@sba923
Copy link

sba923 commented Sep 30, 2019

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

@valorin
Copy link

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

@willemdh
Copy link

willemdh commented Oct 1, 2019

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

@sba923
Copy link

sba923 commented 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

@zadjii-msft
Copy link
Member

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

@Drugoy
Copy link

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

@zadjii-msft
Copy link
Member

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interaction Interacting with the vintage console window (as opposed to driving via API or hooks) In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
None yet
10 participants