Paste adding extra new lines #12865

Closed
opened 2026-01-31 03:27:10 +00:00 by claunia · 8 comments
Owner

Originally created by @justmobilize on GitHub (Mar 4, 2021).

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

Originally created by @justmobilize on GitHub (Mar 4, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none 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 <!-- A description of how to trigger this bug. --> 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 <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> I should get this, everything pasted together: ![image](https://user-images.githubusercontent.com/1547881/110021261-5e811080-7cdf-11eb-8f71-c73a92527627.png) # Actual behavior <!-- What's actually happening? --> I get this: ![image](https://user-images.githubusercontent.com/1547881/110021127-385b7080-7cdf-11eb-9131-17dbbda41d4d.png) Which obviously will cause errors
claunia added the Needs-TriageNeeds-Tag-FixNeeds-Attention labels 2026-01-31 03:27:10 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Mar 4, 2021):

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 commented on GitHub (Mar 4, 2021): 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.
Author
Owner

@justmobilize commented on GitHub (Mar 4, 2021):

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

Installed v1.7.572.0

@justmobilize commented on GitHub (Mar 4, 2021): @zadjii-msft thanks, but sadly no. Got the same results. Installed v1.7.572.0
Author
Owner

@skyline75489 commented on GitHub (Mar 5, 2021):

Like Dustin said in https://github.com/microsoft/terminal/issues/9364#issuecomment-789992943 you may need to use a newer version of Win32-OpenSSH in order to make the bracketed paste work over SSH.

@skyline75489 commented on GitHub (Mar 5, 2021): Like Dustin said in https://github.com/microsoft/terminal/issues/9364#issuecomment-789992943 you may need to use a newer version of Win32-OpenSSH in order to make the bracketed paste work over SSH.
Author
Owner

@justmobilize commented on GitHub (Mar 5, 2021):

Huzzah! That works.

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

@justmobilize commented on GitHub (Mar 5, 2021): Huzzah! That works. Will the newer version of both of these be released soon?
Author
Owner

@skyline75489 commented on GitHub (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.

@skyline75489 commented on GitHub (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.
Author
Owner

@WSLUser commented on GitHub (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.

@WSLUser commented on GitHub (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.
Author
Owner

@trevor-pope commented on GitHub (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.

@trevor-pope commented on GitHub (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.
Author
Owner

@gousaiyang commented on GitHub (Nov 1, 2021):

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

@gousaiyang commented on GitHub (Nov 1, 2021): @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`](https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1519) (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](https://github.com/prompt-toolkit/python-prompt-toolkit/blob/df8246cf03deec681a521c03a12a68d712158e24/prompt_toolkit/input/win32.py#L266). 2. Additionally, by [registering a handler for Ctrl-V key event](https://github.com/ipython/ipython/commit/589822493192889f8d6902f3461ae63e0040ff5f) 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 in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12865