Skip to content

Commit c197e7e

Browse files
authored
Fix 'Shift+Backspace/Escape' to work the same as 'Backspace/Escape' on Windows (#898)
1 parent 546dc19 commit c197e7e

8 files changed

+101
-3
lines changed

PSReadLine/ReadLine.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ void CallPossibleExternalApplication(Action action)
572572

573573
void ProcessOneKey(PSKeyInfo key, Dictionary<PSKeyInfo, KeyHandler> dispatchTable, bool ignoreIfNoAction, object arg)
574574
{
575+
var consoleKey = key.AsConsoleKeyInfo();
576+
575577
// Our dispatch tables are built as much as possible in a portable way, so for example,
576578
// we avoid depending on scan codes like ConsoleKey.Oem6 and instead look at the
577579
// PSKeyInfo.Key. We also want to ignore the shift state as that may differ on
@@ -585,15 +587,15 @@ void ProcessOneKey(PSKeyInfo key, Dictionary<PSKeyInfo, KeyHandler> dispatchTabl
585587
// shift hadn't be pressed. This cleanly allows Shift+Backspace without adding a key binding.
586588
if (key.Shift && !key.Control && !key.Alt)
587589
{
588-
var c = key.KeyChar;
590+
var c = consoleKey.KeyChar;
589591
if (c != '\0' && char.IsControl(c))
590592
{
591-
key = PSKeyInfo.From(key.KeyChar);
593+
key = PSKeyInfo.From(consoleKey.Key);
592594
dispatchTable.TryGetValue(key, out handler);
593595
}
594596
}
595597
}
596-
var consoleKey = key.AsConsoleKeyInfo();
598+
597599
if (handler != null)
598600
{
599601
if (handler.ScriptBlock != null)

test/KeyBindingsTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,19 @@ public void ShowKeyBindings()
4747
TestSetup(KeyMode.Vi);
4848
Test("", Keys(Enumerable.Repeat(_.Ctrl_Alt_Question, 3)));
4949
}
50+
51+
[SkippableFact]
52+
public void ShiftBackspace()
53+
{
54+
TestSetup(KeyMode.Cmd);
55+
Test("aa", Keys("aaa", _.Shift_Backspace));
56+
}
57+
58+
[SkippableFact]
59+
public void ShiftEscape()
60+
{
61+
TestSetup(KeyMode.Cmd);
62+
Test("", Keys("aaa", _.Shift_Escape));
63+
}
5064
}
5165
}

test/KeyInfo-en-US-linux.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,20 @@
958958
"Modifiers": "0",
959959
"Investigate": false
960960
},
961+
{
962+
"Key": "Shift+Backspace",
963+
"KeyChar": "\u007f",
964+
"ConsoleKey": "Backspace",
965+
"Modifiers": "0",
966+
"Investigate": false
967+
},
968+
{
969+
"Key": "Shift+Escape",
970+
"KeyChar": "\u001b",
971+
"ConsoleKey": "Escape",
972+
"Modifiers": "0",
973+
"Investigate": false
974+
},
961975
{
962976
"Key": "Alt+F1",
963977
"KeyChar": "\u0000",

test/KeyInfo-en-US-windows.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,18 @@
13011301
"ConsoleKey": "UpArrow",
13021302
"Modifiers": "Shift"
13031303
},
1304+
{
1305+
"Key": "Shift+Backspace",
1306+
"KeyChar": "\b",
1307+
"ConsoleKey": "Backspace",
1308+
"Modifiers": "Shift"
1309+
},
1310+
{
1311+
"Key": "Shift+Escape",
1312+
"KeyChar": "\u001b",
1313+
"ConsoleKey": "Escape",
1314+
"Modifiers": "Shift"
1315+
},
13041316
{
13051317
"Key": "Spacebar",
13061318
"KeyChar": " ",

test/KeyInfo-fr-FR-windows.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,20 @@
14971497
"Modifiers": "Shift",
14981498
"Investigate": false
14991499
},
1500+
{
1501+
"Key": "Shift+Backspace",
1502+
"KeyChar": "\b",
1503+
"ConsoleKey": "Backspace",
1504+
"Modifiers": "Shift",
1505+
"Investigate": false
1506+
},
1507+
{
1508+
"Key": "Shift+Escape",
1509+
"KeyChar": "\u001b",
1510+
"ConsoleKey": "Escape",
1511+
"Modifiers": "Shift",
1512+
"Investigate": false
1513+
},
15001514
{
15011515
"Key": "Shift+UpArrow",
15021516
"KeyChar": "\u0000",

test/KeyInfo-pl-PL-linux.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@
279279
"Modifiers": "Shift",
280280
"Investigate": false
281281
},
282+
{
283+
"Key": "Shift+Backspace",
284+
"KeyChar": "\u007f",
285+
"ConsoleKey": "Backspace",
286+
"Modifiers": "0",
287+
"Investigate": false
288+
},
289+
{
290+
"Key": "Shift+Escape",
291+
"KeyChar": "\u001b",
292+
"ConsoleKey": "Escape",
293+
"Modifiers": "0",
294+
"Investigate": false
295+
},
282296
{
283297
"Key": "j",
284298
"KeyChar": "j",

test/KeyInfo-pl-PL-windows.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,20 @@
727727
"Modifiers": "Shift",
728728
"Investigate": false
729729
},
730+
{
731+
"Key": "Shift+Backspace",
732+
"KeyChar": "\b",
733+
"ConsoleKey": "Backspace",
734+
"Modifiers": "Shift",
735+
"Investigate": false
736+
},
737+
{
738+
"Key": "Shift+Escape",
739+
"KeyChar": "\u001b",
740+
"ConsoleKey": "Escape",
741+
"Modifiers": "Shift",
742+
"Investigate": false
743+
},
730744
{
731745
"Key": "Ctrl+y",
732746
"KeyChar": "\u0019",

test/KeyInfo-ru-RU-windows.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,20 @@
741741
"Modifiers": "Shift",
742742
"Investigate": false
743743
},
744+
{
745+
"Key": "Shift+Backspace",
746+
"KeyChar": "\b",
747+
"ConsoleKey": "Backspace",
748+
"Modifiers": "Shift",
749+
"Investigate": false
750+
},
751+
{
752+
"Key": "Shift+Escape",
753+
"KeyChar": "\u001b",
754+
"ConsoleKey": "Escape",
755+
"Modifiers": "Shift",
756+
"Investigate": false
757+
},
744758
{
745759
"Key": "5",
746760
"KeyChar": "5",

0 commit comments

Comments
 (0)