microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
94.88k stars 8.22k forks source link

Backspace deletes whole word instead of character #14338

Open umnyaga opened 1 year ago

umnyaga commented 1 year ago

Windows Terminal version

1.15.2874.0, 1.16.2641.0

Windows build number

10.0.19043.0

Other Software

No response

Steps to reproduce

type several word in shell command line and press backspace.

Expected Behavior

Backspace deletes character left unstead od whole words

Actual Behavior

In Power Shell or Cmd running in Windows Terminal, pressing backspace deletes whole word left instead of character left. It's interesting, once ssh to remote linux host from that powershell window, backspace behavior becomes normal. I found it on my home PC and on at workplace's PC.

zadjii-msft commented 1 year ago

What keyboard layout are you using? I'm betting there's an encoding glitch where we're treating the Bksp as Ctrl+Bksp for some reason.

umnyaga commented 1 year ago

I use HP C3758A and another Lenovo standard, do not know the model number, but it is simple one without any fanciness. Both standard US layout. These two keyboards belong to most standard ones as it gets.

zadjii-msft commented 1 year ago

Hmm #13894

umnyaga commented 1 year ago

Hmm, interesting. I've never tried, but Ctrl-Backspace deletes character left.

carlos-zamora commented 1 year ago

Our leading theory is that this is being caused by referencing uninitialized memory. That should be fixed via https://github.com/microsoft/terminal/pull/14345. So we'll hope that fixes this, and circle back around after it's merged.

zadjii-msft commented 1 year ago

@umnyaga can you try out v1.15.3465.0 / v1.15.3466. (or the latest 1.16 build), and see if that fixes this/?

umnyaga commented 1 year ago

@umnyaga can you try out v1.15.3465.0 / v1.15.3466. (or the latest 1.16 build), and see if that fixes this/?

@zadjii-msft just tried, there is no changes in behavior, backspace still deletes a word left.

zadjii-msft commented 1 year ago

Huh. The assumption here is that DECBKM is defaulting to on for you, but there's pretty much no reason that should be. There would need to be some sort of \x1b[?67h in your profile.ps1 or something, but then I wouldn't expect this to repro in CMD as well.

I wonder if we could test that... I don't think pwsh uses VT for input events at all, so that's not

Wait a second, neither CMD nor pwsh would be using VT input. So this shouldn't be that at all. It's like there's something else swapping Bkspc and DEL

zadjii-msft commented 1 year ago

Can you try repro'ing this with the debug tap to get a trace of all the input and output? Once the bug starts occurring, send us a screenshot and we might be able to figure out what the Terminal thinks it's getting here.

j4james commented 1 year ago

@zadjii-msft FYI, you can kind of trick the terminal into enabling DECBKM by exploiting the way we pass through modes that aren't recognised. However, that requires the Win32 input mode is disabled as well. For example, in PowerShell you'd need to do something like this:

echo "`e[?9001;9999l"
echo "`e[?67;9999h"

I wouldn't have thought it likely that anyone is doing that accidentally, though. But if DECBKM is to blame, you ought to be able to "fix" it with something like this:

echo "`e[?67;9999l"
umnyaga commented 1 year ago

Can you try repro'ing this with the debug tap to get a trace of all the input and output? Once the bug starts occurring, send us a screenshot and we might be able to figure out what the Terminal thinks it's getting here.

Here is what I've got image

j4james commented 1 year ago

That's really weird. It appears that the backspace key is somehow bypassing the Win32 input mode encoding. We should be seeing keydown and keyup events for a VK_BACK key, (i.e. ␛[8;14;8;1;32;1_ ␛[8;14;8;0;32;1_), but instead we're getting a single character. I have no idea how that could happen.

zadjii-msft commented 1 year ago

Wow, uh, me neither. Maybe it's coming through on the... character handler, instead of the key one? This is super bizarre. Turning off win32 input probably wouldn't fix this either, then, cause the event would still get sent as a BS char, which would still get translated wrong.

clau3107 commented 1 year ago

@zadjii-msft FYI, you can kind of trick the terminal into enabling DECBKM by exploiting the way we pass through modes that aren't recognised. However, that requires the Win32 input mode is disabled as well. For example, in PowerShell you'd need to do something like this:

echo "`e[?9001;9999l"
echo "`e[?67;9999h"

I wouldn't have thought it likely that anyone is doing that accidentally, though. But if DECBKM is to blame, you ought to be able to "fix" it with something like this:

echo "`e[?67;9999l"

This fixed it for me, thank you!

andersforsgren commented 1 month ago

This is still an intermittent issue in cmd in the latest version (1.20.11781.0) and the ^[[?67;9999l fix does not help it.