terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Window Terminal sporadically fails to trim trailing white spaces.

Open jeffpkamp opened this issue 1 year ago • 16 comments

Windows Terminal version

1.20.11781.0

Windows build number

10.0.19043 Build 19043

Other Software

This happens no matter where I am copying from.

Steps to reproduce

Open terminal, copy and paste into a new terminal window. The behavior is sporadic, but happens with often. It makes it very hard to work in the terminal.

Expected Behavior

pasted text will have the excess white space at the end of the line removed

Actual Behavior

pasted text is treated like it was a single line that wrapped around, leading to long white spaces and no line breaks.

Behavior is sporadic. The problem is on the copy window side.

Example: Below data was copied and pasted. Some of the white space is removed, some is not.

                                                                                                                               secondary={}                                                                                                                      r=requests.get(HTML).content.decode().split("\n")                                                                                 for x in r[1:]:
    if x:
        if "NONE" not in x:
            x=re.split("[\t ]",x)
            pos=x[0].replace("_"," ")
            if pos not in secondary:
                secondary[pos]=set()
            for v in x[1:]:
                if "(" not in v:
                    secondary[pos]=secondary[pos]|set([v])

I add a few newlines above the text and now it copies correctly, but this is not a consistent fix

secondary={}
r=requests.get(HTML).content.decode().split("\n")
for x in r[1:]:
    if x:
        if "NONE" not in x:
            x=re.split("[\t ]",x)
            pos=x[0].replace("_"," ")
            if pos not in secondary:
                secondary[pos]=set()
            for v in x[1:]:
                if "(" not in v:
                    secondary[pos]=secondary[pos]|set([v])

jeffpkamp avatar Sep 04 '24 00:09 jeffpkamp

Sorry, just noted this behavior. Sometimes it puts a newline in where the line wraps.

jeffpkamp avatar Sep 04 '24 00:09 jeffpkamp

Does this repro on 1.22/?

https://github.com/microsoft/terminal/releases/tag/v1.22.2362.0

zadjii-msft avatar Sep 04 '24 10:09 zadjii-msft

Got it installed. Give me a few days to test it out and see if the buggy behavior appears

jeffpkamp avatar Sep 04 '24 23:09 jeffpkamp

It has worked correctly on the new version for a few days now. I am now testing it out on a different computer just to make sure.

jeffpkamp avatar Sep 09 '24 14:09 jeffpkamp

I am still seeing the inappropriate pasting behavior on the new computer I am using it on.

jeffpkamp avatar Sep 09 '24 15:09 jeffpkamp

I can confirm I am still seeing the issue on the original computer with the new release of the terminal.

I should also note that sometimes I can get it to stop by doing things like resizing the window? Doesn't always work, but sometimes it does.

jeffpkamp avatar Sep 13 '24 16:09 jeffpkamp

Thanks for filing! What shell or other application are you using /?

carlos-zamora avatar Sep 25 '24 21:09 carlos-zamora

I am using bash shell. The problem does not seem to matter if I am in the shell environment or copying from a text editor like vim or less. Once it starts, it will persist until I do something that changes the state of the screen like resizing, though this does not get rid of it every time.

jeffpkamp avatar Sep 30 '24 14:09 jeffpkamp

Sorry - are you using WSL, Cygwin, or msys2?

DHowett avatar Sep 30 '24 16:09 DHowett

I am using wsl2

jeffpkamp avatar Sep 30 '24 16:09 jeffpkamp

Steps to reproduce Open terminal, copy and paste into a new terminal window. The behavior is sporadic, but happens with often. It makes it very hard to work in the terminal.

If I paste 10 lines, sometimes, 1-3 lines are appended in one line. I set vim to nowrap, it seems like I miss 2 lines.

Edition Windows 11 Enterprise Version 23H2 Installed on ‎2/‎23/‎2024 OS build 22631.4460 Experience Windows Feature Experience Pack 1000.22700.1047.0

Windows Terminal Version: 1.21.2911.0

mishuang2017 avatar Nov 27 '24 02:11 mishuang2017

I'm experiencing this too. Seems to happen especially when I select rectangular block from lines where there are more text on right-hand side outside my selection.

anttiah avatar Dec 02 '24 13:12 anttiah

We think that this'll be a lot better with v1.22. You can try it out with WT Preview (which you can get over in the releases page). Please let us know if that fixes your issue, thanks! 🙂

carlos-zamora avatar Jan 13 '25 21:01 carlos-zamora

Terminal (Unpackaged) Version: 1.22.241118002-preview

Unfortunately, it still has problem:

# tc -s filter show dev enp8s0f0_0 ingress
filter parent ffff: protocol ip pref 1 flower chain 0
filter parent ffff: protocol ip pref 1 flower chain 0 handle 0x1
  dst_mac e4:1d:2d:fd:8b:02
  eth_type ipv4
  ip_proto icmp
  skip_sw
  in_hw in_hw_count 1
        action order 1: tunnel_key  set
        src_ip 49.0.10.60
        dst_ip 46.0.10.180
        key_id 98
        dst_port 4789
        csum pipe
         index 1 ref 1 bind 1 installed 789 sec used 789 sec
        Action statistics:                                                                                                                                                                          Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
        backlog 0b 0p requeues 0
        used_hw_stats delayed

        action order 2: mirred (Egress Redirect to device vxlan1) stolen
        index 1 ref 1 bind 1 installed 789 sec used 749 sec
        Action statistics:
        Sent 47064 bytes 318 pkt (dropped 0, overlimits 0 requeues 0)
        Sent software 0 bytes 0 pkt
        Sent hardware 47064 bytes 318 pkt
        backlog 0b 0p requeues 0
        used_hw_stats delayed

mishuang2017 avatar Jan 20 '25 03:01 mishuang2017

Just wanted to add... it will be so GREAT when this gets fixed. Makes me miss mintty when I create rectangular selections.

caffeinejolt avatar Apr 16 '25 17:04 caffeinejolt

It would be helpful to me if the option to either trim trailing white space, or not trim trailing white space, could be exposed in something like a right-click menu.

I often find myself needing to quickly check the field width of items printed to the screen.

Image

The white space being trimmed in this case is "trailing" only from the perspective of the copy/paste buffer, not the screen buffer.

My workaround is to select one extra character, paste, then backspace over the extra character.

Image

--

My dream feature would be to somehow have the screen buffer remember exactly the white space which preceded the newline character, so that I could cat a file to the terminal, select the text, paste it into another text editor, and get precisely the same file.

AltitudeApps avatar Apr 26 '25 15:04 AltitudeApps