Terminal: Terminal breaks copied text at window line wraps, even when the text has no new-line characters

Created on 25 Mar 2020  Â·  15Comments  Â·  Source: microsoft/terminal

I recall this was working in older versions of Terminal and in Windows' copy of the console window, but it seems to have broken more recently.

Environment

Windows build number: 18363.720 (Windows 10 ver. 1909 with update KB4551762)
Windows Terminal version: 0.10.781.0

Steps to reproduce

  1. Open this file in an editor: C:\Windows\System32\WindowsCodecsRaw.txt
  2. Notice that the last line of the file "THE SOFTWARE IS PROVIDED".... is over 500 characters long.
  3. Open Terminal to the Command Prompt or PowerShell, then run:
    type C:\Windows\System32\WindowsCodecsRaw.txt
  4. Drag to select text from multiple in-window lines of the last line of the file, then right-click to copy.
  5. Paste the clipping into a new file in Notepad.

Expected and actual behavior

Expected: the text is all on one line.
Actual: the text is split into multiple lines.

Area-TerminalControl Issue-Bug Priority-1 Product-Terminal Resolution-Fix-Committed

Most helpful comment

@paul-michalik you're in luck because I'm working on this pretty aggressively over in #5181

All 15 comments

Here's my profiles.json file in case that matters, though I can't see anything that stands out:

{
  "$schema": "https://aka.ms/terminal-profiles-schema",
  "defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
  "initialCols": 120,
  "initialRows": 40,
  "profiles": {
    "defaults": {
      "fontFace": "Consolas",
      "fontSize": 11,
      "historySize": 9999
    },
    "list": [
      {
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "Command Prompt",
        "commandline": "%comspec%",
        "startingDirectory": "C:\\Windows\\System32",
        "hidden": false
      },
      {
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
        "startingDirectory": "C:\\Windows\\System32",
        "hidden": false
      },
      {
        "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
        "hidden": false,
        "name": "Ubuntu-18.04",
        "source": "Windows.Terminal.Wsl"
      },
      {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
        "hidden": false,
        "name": "Azure Cloud Shell",
        "source": "Windows.Terminal.Azure"
      }
    ]
  },
  "schemes": [],
  "keybindings": []
}

I have the issue. Seems to have been introduced in v0.10.761.0.

Okay so we’ve been seeing various reports of this in the most recent build, despite doing some work to specifically handle this better.

Turns out, it’ll only happen when it causes the viewport to scroll – like when you’re emitting text at the bottom of the window. This explains why it seems like sometimes it works fine and other times it doesn’t.

Now that we’ve got a consistent repro, it should make debugging _much_ easier.

Turns out, it’ll only happen when it causes the viewport to scroll – like when you’re emitting text at the bottom of the window.

I'm not sure that's quite right? I just tried starting Terminal with the profiles.json above and typing out the file, which doesn't cause a scroll of the displayed area as far as I can see. After copying the first 3 displayed lines of the "THE SOFTWARE" line of text (up to "OR ANY DAMAGES W"), I get 2 lines in Notepad.

I mean, here's what I'm seeing when I do type C:\Windows\System32\WindowsCodecsRaw.txt with a fresh WT:
image
(note the line numbers in Sublime, behind WT)

Then, performing it a second time, which causes the scrolling:
image

@zadjii-msft I can constantly reproduce it even when the viewport does not scroll. I found it's related to this:

https://github.com/microsoft/terminal/blob/d47da2d617dbda3a46a1a052122536eca123b722/src/buffer/out/textBuffer.cpp#L1543

If I remove this mechanism, the copied text will not have extra new-lines.

For me as an Admin and DevOps this is a major issue - for example: ssh pubkeys are breaking when being copied and pasted.

For anyone who need to downgrade due to this, I can recommend to do this via choco like this:

choco list microsoft-windows-terminal --all
choco uninstall microsoft-windows-terminal
choco install microsoft-windows-terminal --version 0.10.761.0

Don't forget to store your current profile.json somewhere - when you uninstall the Terminal app, the profile will be resetted to defaults!

Hope this helps.

@hirschnase

For me as an Admin and DevOps this is a major issue - for example: ssh pubkeys are breaking when being copied and pasted.
For anyone who need to downgrade due to this, I can recommend to do this via choco like this:
choco list microsoft-windows-terminal --all
choco uninstall microsoft-windows-terminal
choco install microsoft-windows-terminal --version 0.10.761.0

The version 0.10.761.0 exhibits the same behavior. You need to go to 0.9.433.0. And even there, the problem remains when you copy-paste between different shells. For example, copy from CMD and paste into Git/bin/bash.exe shell in a different tab works while the same operation in opposite direction does not work. This seems to be a problem of the underlying shells though... Would be great if this would be handled by wt.exe!

@paul-michalik you're in luck because I'm working on this pretty aggressively over in #5181

As a workaround for now, resize the terminal window (enlarge or shrink) and try to copy&paste it again. It works for me.

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

Handy links:

Does anyone know what's needed to get this into Cygwin?

This is still broken in "1.0.1811.0".

Still broken in Cygwin too fwiw.

@nvonwolf This was a pretty specific scenario that _should_ have been fixed by #5181. If you're still seeing this behavior, could you file a new issue with exact repro steps, so we could track the new regression? Thanks!

Was this page helpful?
0 / 5 - 0 ratings