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

Paste adding extra new lines #9378

Closed
justmobilize opened this issue Mar 4, 2021 · 8 comments
Closed

Paste adding extra new lines #9378

justmobilize opened this issue Mar 4, 2021 · 8 comments
Labels
Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting

Comments

@justmobilize
Copy link

Environment

Windows build number: `Microsoft Windows [Version 10.0.19042.804]`
Windows Terminal version (if applicable): `1.6.10571.0`

Any other software?

Steps to reproduce

I am constantly ssh-ing to a box, starting up iPython, pasting a block of code (with methods), and then running selected methods. Currently I've been using putty and this works great.

Switching to Windows Terminal I tried this, and it pastes one line at a time, and thus errors out.

I can do awkward things like %cpaste in iPython or :set paste in Vim, but that makes things more complicated

For example pasting:

def add(a, b):
  # add method

  val = a + b

  return val

print(add(1,2))

Expected behavior

I should get this, everything pasted together:
image

Actual behavior

I get this:
image

Which obviously will cause errors

@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 4, 2021
@zadjii-msft
Copy link
Member

This sounds like something that bracketed paste (#395) might just fix. Can you try installing Windows Terminal Preview, and see if that fixes it? Preview added support for bracketed paste in 1.7.

@zadjii-msft zadjii-msft added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 4, 2021
@justmobilize
Copy link
Author

@zadjii-msft thanks, but sadly no. Got the same results.

Installed v1.7.572.0

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Mar 4, 2021
@skyline75489
Copy link
Collaborator

Like Dustin said in #9364 (comment) you may need to use a newer version of Win32-OpenSSH in order to make the bracketed paste work over SSH.

@justmobilize
Copy link
Author

Huzzah! That works.

Will the newer version of both of these be released soon?

@skyline75489
Copy link
Collaborator

skyline75489 commented Mar 5, 2021

The 1.7 preview will become 1.7 stable about the end of the month, or maybe next month.

You know, the preview version is actually good enough for most people I think. The preview version is released after being tested inside Microsoft. I've been using preview like forever.

I do not know about the release schedule of Win32-OpenSSH, though. That's probably what @DHowett can answer.

@WSLUser
Copy link
Contributor

WSLUser commented Mar 5, 2021

I do not know about the release schedule of Win32-OpenSSH

Well there's been no movement on it for over a year and they're quite a few releases behind the mainstream ssh. By now we should be at 8.5 but 8.1 is the last release. The Powershell team is supposed to be responsible for it but seems like it's just not a priority for them. I almost consider it abandonware for that reason.

@trevor-pope
Copy link

trevor-pope commented Oct 12, 2021

Still having this issue in windows terminal (no SSH or anything). Strangely enough, I was on version 1.8, and never had this issue until today. I'm not sure what changed (I did install WSL and Ubuntu the other day, though I'm not using it, but maybe that has something to do with it), but I updated to the most recent (version: 1.10.2714.0) to try to fix it but no luck. Pasting into ipython will paste individual lines and add indentation to each line.

Edit:
Strangely enough, I tested it on another machine (also on 1.10) and it works just fine. Not sure what's causing it, but it's definitely terminal related as it works fine on a regular cmd.

@gousaiyang
Copy link

@trevor-pope I'm having a similar issue with IPython recently and found a way to solve it. I guess you might be having the same problem and I want to share my findings:

I'm using IPython in Windows Terminal. The profile is "commandline": "ipython.exe", so this is just running the IPython in Windows, not an IPython in WSL, and not through SSH, just on my local machine. I observed incorrect indentation when pasting multiline code into IPython. It was working correctly for a long time but started to break recently. I was originally suspecting this to be a Windows Terminal problem, but it turned out to be a bug in prompt-toolkit (a dependency of IPython) since version 3.0.20.

On Windows, IPython does not emit \x1b[?2004h to inform terminal of bracketed paste support. Instead, it utilizes the following two mechanisms to achieve bracketed paste:

  1. By utilizing prompt-toolkit to recognize multiline paste as bracketed paste.
  2. Additionally, by registering a handler for Ctrl-V key event to improve the paste behavior.

When using Windows Terminal, the second mechanism (handler for Ctrl-V key event) will not work because Ctrl-V is already handled by Windows Terminal (as in the default settings.json) and not passed to the application. The application received pasted text instead of the Ctrl-V key event. When the first mechanism (prompt-toolkit) is buggy, IPython will fail to correctly handle multiline paste.

When using the traditional conhost, the incorrect indentation does not happen even when prompt-toolkit is buggy because the second mechanism (handler for Ctrl-V key event) is working there. If you paste content by "Right clicking conhost window title -> Edit -> Paste", the incorrect indentation will show up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting
Projects
None yet
Development

No branches or pull requests

6 participants