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

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

Closed
metathinker opened this issue Mar 25, 2020 · 17 comments · Fixed by #5181
Assignees
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@metathinker
Copy link
Contributor

metathinker commented Mar 25, 2020

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.

@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 Mar 25, 2020
@metathinker
Copy link
Contributor Author

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": []
}

@mg-christian-axelsson
Copy link

mg-christian-axelsson commented Mar 25, 2020

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

@zadjii-msft
Copy link
Member

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.

@zadjii-msft zadjii-msft self-assigned this Mar 25, 2020
@zadjii-msft zadjii-msft added Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. labels Mar 25, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Mar 25, 2020
@zadjii-msft zadjii-msft added this to the Terminal v1.0 milestone Mar 25, 2020
@metathinker
Copy link
Contributor Author

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.

@zadjii-msft
Copy link
Member

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

@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Mar 26, 2020
@skyline75489
Copy link
Collaborator

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

// apply CR/LF to the end of the final string, unless we're the last line.

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

@ghost
Copy link

ghost commented Apr 1, 2020

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.

@paul-michalik
Copy link

paul-michalik commented Apr 7, 2020

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

@zadjii-msft
Copy link
Member

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

@hmageste
Copy link

hmageste commented Apr 7, 2020

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

@ghost ghost closed this as completed in #5181 Apr 9, 2020
@ghost ghost removed the In-PR This issue has a related PR label Apr 9, 2020
ghost pushed a commit that referenced this issue Apr 9, 2020
Now that the Terminal is doing a better job of actually marking which
lines were and were not wrapped, we're not always copying lines as
"wrapped" when they should be. We're more correctly marking lines as not
wrapped, when previously we'd leave them marked wrapped.

The real problem is here in the `ScrollFrame` method - we'd manually
newline the cursor to make the terminal's viewport shift down to a new
line. If we had to scroll the viewport for a _wrapped_ line, this would
cause the Terminal to mark that line as broken, because conpty would
emit an extra `\n` that didn't actually exist.

This more correctly implements `ScrollFrame`. Now, well move where we
"thought" the cursor was, so when we get to the next `PaintBufferLine`,
if the cursor needs to newline for the next line, it'll newline, but if
we're in the middle of a wrapped line, we'll just keep printing the
wrapped line.

A couple follow up bugs were found to be caused by the same bad logic.
See #5039 and #5161 for more details on the investigations there.

## References

* #4741 RwR, which probably made this worse
* #5122, which I branched off of 
* #1245, #357 - a pair of other conpty wrapped lines bugs
* #5228 - A followup issue for this PR

## PR Checklist
* [x] Closes #5113
* [x] Closes #5180 (by fixing DECRST 25)
* [x] Closes #5039
* [x] Closes #5161 (by ensuring we only `removeSpaces` on the actual
  bottom line)
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed

* Checked the cases from #1245, #357 to validate that they still work
* Added more and more tests for these scenarios, and then I added MORE
  tests
* The entire team played with this in selfhost builds
@ghost ghost added the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Apr 9, 2020
@ghost
Copy link

ghost commented Apr 22, 2020

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

Handy links:

@ElvenSpellmaker
Copy link

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

@ghost
Copy link

ghost commented Jul 13, 2020

This is still broken in "1.0.1811.0".

@ElvenSpellmaker
Copy link

Still broken in Cygwin too fwiw.

@zadjii-msft
Copy link
Member

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

@lindhe
Copy link

lindhe commented Oct 11, 2023

I'm at 1.17.11461.0 and still have this issue. Not with scrolling, but always. :(

Anything I can do about it? Should I open a new issue or stick to this one?

@zadjii-msft
Copy link
Member

@lindhe I'd recommend filing a new issue, with more details about your setup. Also, I'd recommend trying out Terminal Preview - I'm pretty sure there were some fixes in the 1.18/1.19 timeframe that might have helped with some scenarios around this topic.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants