Add a third option which replaces newlines by spaces when pasting content with multiple lines #12894

Closed
opened 2026-01-31 03:28:14 +00:00 by claunia · 13 comments
Owner

Originally created by @FremyCompany on GitHub (Mar 6, 2021).

Description of the new feature/enhancement

When pasting in the Terminal a command line that ends with a line break, my options are either to paste and run the command, or abort the operation. Most of the times, I actually want to paste while trimming the trailing line break, such that I can edit the command I am pasting.

image

Proposed technical implementation details (optional)

When pasting, a new button would appear in the confirmation dialog, that would allow to paste while trimming line breaks (if the string contains line breaks that are not trimmed, replace them by a space?)

Originally created by @FremyCompany on GitHub (Mar 6, 2021). # Description of the new feature/enhancement When pasting in the Terminal a command line that ends with a line break, my options are either to paste and run the command, or abort the operation. Most of the times, I actually want to paste while trimming the trailing line break, such that I can edit the command I am pasting. ![image](https://user-images.githubusercontent.com/364405/110218078-ede11c00-7eb7-11eb-8527-1ca33ea88f01.png) # Proposed technical implementation details (optional) When pasting, a new button would appear in the confirmation dialog, that would allow to paste while trimming line breaks (if the string contains line breaks that are not trimmed, replace them by a space?)
Author
Owner

@FremyCompany commented on GitHub (Mar 6, 2021):

Adding a third button might require some refactoring, because the dialog is only meant to have two buttons:

f26c246c7c/src/cascadia/TerminalApp/TerminalPage.cpp (L2146-L2165)

@FremyCompany commented on GitHub (Mar 6, 2021): Adding a third button might require some refactoring, because the dialog is only meant to have two buttons: https://github.com/microsoft/terminal/blob/f26c246c7c081c0222dd8ebd4738f6a0d574f66c/src/cascadia/TerminalApp/TerminalPage.cpp#L2146-L2165
Author
Owner

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

I don't hate this idea. But with bracketed paste feature in 1.7, this does not really bother me when I'm using bash/zsh. The shell will not execute the command and let you edit it. Sadly powershell does not support bracketed paste, though.

@skyline75489 commented on GitHub (Mar 7, 2021): I don't hate this idea. But with bracketed paste feature in 1.7, this does not really bother me when I'm using bash/zsh. The shell will not execute the command and let you edit it. Sadly powershell does not support bracketed paste, though.
Author
Owner

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

I don't think this is a terrible idea. Looks like the ContentDialog supports 3 buttons, it would just take a bit of refactoring.
image

@zadjii-msft commented on GitHub (Mar 8, 2021): I don't think this is a terrible idea. Looks like the `ContentDialog` supports 3 buttons, it would just take a bit of refactoring. ![image](https://user-images.githubusercontent.com/18356694/110317076-3e986800-7fd1-11eb-84c0-82ffa683a5d9.png)
Author
Owner

@Nacimota commented on GitHub (Mar 11, 2021):

I've just taken a crack at this and I think I've got it working without any substantial refactoring at all. I'm still pretty intimidated by C++ though, so I'm not sure if I'm doing anything stupid/careless, but I'm happy to submit this in a PR if anyone wants to take a look.

@Nacimota commented on GitHub (Mar 11, 2021): I've just taken a crack at this and I think I've got it working without any substantial refactoring at all. I'm still pretty intimidated by C++ though, so I'm not sure if I'm doing anything stupid/careless, but I'm happy to submit this in a PR if anyone wants to take a look.
Author
Owner

@chenzhiwei commented on GitHub (Aug 4, 2021):

Could you simply add an option to terminal, the values can be: 1. trim trailing newline, 2. don't trim, 3, interactive dialog

@chenzhiwei commented on GitHub (Aug 4, 2021): Could you simply add an option to terminal, the values can be: 1. trim trailing newline, 2. don't trim, 3, interactive dialog
Author
Owner

@zadjii-msft commented on GitHub (Sep 13, 2021):

Merging some discussion from #10502

I do think we should be more intelligent here... text that is a single line and ends in a newline with no further content should just strip it by default, I think. I am opposed to adding a button to every paste dialog that folks will have to process when they paste. Perhaps there's a middle ground!

@zadjii-msft commented on GitHub (Sep 13, 2021): Merging some discussion from #10502 > I do think we should be more intelligent here... text that is a single line and ends in a newline with no further content should just strip it by default, I think. I am opposed to adding a button to every paste dialog that folks will have to process when they paste. Perhaps there's a middle ground!
Author
Owner

@zadjii-msft commented on GitHub (Sep 15, 2021):

After reading all the discussion on this topic, I wonder if there's really a need for the "strip line breaks and replace with spaces" button. There's really two cases here, right?

  • I copied a singular line of text, that happened to have a trailing newline, and tried pasting it, and got this warning in my face.
    • How often do people actually want to paste the newline as well? Are people really intentionally copying a command and a newline so they can paste&go with that command?
    • If they are, is forcing them to paste AND THEN PRESS ENTER really that workflow breaking?
  • I copied a bunch of lines of text, and got this warning in my face.
    • This to me does feel like "I wanted to paste a bunch of commands and execute them"
    • Who's really wanting to paste all these lines with spaces between them (instead of newlines) here?

Relevant settings below.

  • multiLinePasteWarning
  • paste action, which could be enhanced with properties if we really wanted.
    • for ex: convertNewlinesToSpaces could be an arg here? Paste (convert newlines to spaces) in the command palette
    • trimSingleTrailingNewline (default:true) for "if there's just one newline at the end then trim that", so folks could set this to false to be able to paste a command in one go?

</showerthoughts>

@zadjii-msft commented on GitHub (Sep 15, 2021): After reading all the discussion on this topic, I wonder if there's really a need for the "strip line breaks and replace with spaces" button. There's really two cases here, right? * I copied a singular line of text, that happened to have a trailing newline, and tried pasting it, and got this warning in my face. * How often do people actually want to paste the newline as well? Are people really intentionally copying a command and a newline so they can paste&go with that command? * If they are, is forcing them to paste AND THEN PRESS ENTER really that workflow breaking? * I copied a bunch of lines of text, and got this warning in my face. * This to me does feel like "I wanted to paste a bunch of commands and execute them" * Who's really wanting to paste all these lines with spaces between them (instead of newlines) here? Relevant settings below. * [`multiLinePasteWarning`](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/interaction#warn-when-the-text-to-paste-contains-multiple-lines) * [`paste` action](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions#paste), which could be enhanced with properties if we really wanted. - for ex: `convertNewlinesToSpaces` could be an arg here? `Paste (convert newlines to spaces)` in the command palette - `trimSingleTrailingNewline` (default:true) for "if there's just one newline at the end then trim that", so folks could set this to false to be able to paste a command in one go? \</showerthoughts>
Author
Owner

@Nacimota commented on GitHub (Sep 15, 2021):

Who's really wanting to paste all these lines with spaces between them (instead of newlines) here?

After thinking about it myself for a bit, I am inclined to agree with you. My PR on this is pretty stale anyway because we hadn't decided what the button text should be and then I think I just forgot about it. But yes, I am struggling to think of a situation where you would actually want to strip breaks from the middle of the paste. I suppose maybe if you copied from some poorly formatted source (PDFs, for example, move in mysterious ways) wherein the command was supposed to be one line but for some reason contains line breaks? Feels like a stretch, though.

Anecdotally, this warning only shows up for me because either I am indeed pasting multiple commands or I just accidentally copied the wrong thing.

trimSingleTrailingNewline (default:true) for "if there's just one newline at the end then trim that", so folks could set this to false to be able to paste a command in one go?

Automatically trimming the trailing new line makes sense to me, but I wonder does it really matter if it's just one? As long as there's no other characters in between, multiple line breaks at the end of the string seems practically equivalent to a single one to me.

@Nacimota commented on GitHub (Sep 15, 2021): > Who's really wanting to paste all these lines with spaces between them (instead of newlines) here? After thinking about it myself for a bit, I am inclined to agree with you. My PR on this is pretty stale anyway because we hadn't decided what the button text should be and then I think I just forgot about it. But yes, I am struggling to think of a situation where you would actually want to strip breaks from *the middle* of the paste. I suppose maybe if you copied from some poorly formatted source (PDFs, for example, move in mysterious ways) wherein the command was supposed to be one line but for some reason contains line breaks? Feels like a stretch, though. Anecdotally, this warning only shows up for me because either I am indeed pasting multiple commands or I just accidentally copied the wrong thing. > `trimSingleTrailingNewline` (default:true) for "if there's just one newline at the end then trim that", so folks could set this to false to be able to paste a command in one go? Automatically trimming the trailing new line makes sense to me, but I wonder does it really matter if it's just one? As long as there's no other characters in between, multiple line breaks at the end of the string seems practically equivalent to a single one to me.
Author
Owner

@FremyCompany commented on GitHub (Sep 16, 2021):

Single trailing new line stripping sounds good to me as well.

@FremyCompany commented on GitHub (Sep 16, 2021): Single trailing new line stripping sounds good to me as well.
Author
Owner

@zadjii-msft commented on GitHub (Sep 20, 2021):

Talked with the team today - we do feel like the right way forward is just to trim the trailing newline if that's the only one in the paste contents. To quote: "It doesn't make sense to be warned for multiple lines, but copy a single line and try to paste it AND ONLY SEE ONE LINE IN THE DIALOG. That's dumb".

@zadjii-msft commented on GitHub (Sep 20, 2021): Talked with the team today - we do feel like the right way forward is just to trim the trailing newline if that's the only one in the paste contents. To quote: "It doesn't make sense to be warned for multiple lines, but copy a single line and try to paste it AND ONLY SEE ONE LINE IN THE DIALOG. That's dumb".
Author
Owner

@lovef commented on GitHub (Oct 10, 2021):

Hi, I made a try at solving the issue and uploaded a PR for optionally trimming trailing white spaces. It is a feature that I've been missing so I wanted to try it out as it seemed simple, apart from the C++ part

@lovef commented on GitHub (Oct 10, 2021): Hi, I made a try at solving the issue and uploaded a PR for optionally trimming trailing white spaces. It is a feature that I've been missing so I wanted to try it out as it seemed simple, apart from the C++ part
Author
Owner

@shtratos commented on GitHub (Oct 29, 2021):

Huge thanks @lovef, @zadjii-msft and all the contributors!
I was pulling my hair out every time I was trying to paste a command into a terminal. Can't wait for the next release!

@shtratos commented on GitHub (Oct 29, 2021): Huge thanks @lovef, @zadjii-msft and all the contributors! I was pulling my hair out every time I was trying to paste a command into a terminal. Can't wait for the next release!
Author
Owner

@ghost commented on GitHub (Feb 3, 2022):

:tada:This issue was addressed in #11473, which has now been successfully released as Windows Terminal Preview v1.13.10336.0.🎉

Handy links:

@ghost commented on GitHub (Feb 3, 2022): :tada:This issue was addressed in #11473, which has now been successfully released as `Windows Terminal Preview v1.13.10336.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.13.10336.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12894