Skip to content

Commit bc11289

Browse files
committed
Refactored key chords handling
1 parent fbdf7fa commit bc11289

13 files changed

+788
-738
lines changed

PSReadLine/Completion.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ private void MenuCompleteImpl(Menu menu, CommandCompletion completions)
10911091
prependNextKey = true;
10921092

10931093
// without this branch experience doesn't look naturally
1094-
if (_dispatchTable.TryGetValue(nextKey, out var handler) &&
1094+
if (_dispatchTable.TryGetValue(nextKey, out var handlerOrChordDispatchTable) &&
1095+
handlerOrChordDispatchTable.TryGetKeyHandler(out var handler) &&
10951096
(
10961097
handler.Action == CopyOrCancelLine ||
10971098
handler.Action == Cut ||

PSReadLine/ConsoleKeyChordConverter.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ public static ConsoleKeyInfo[] Convert(string chord)
3636
throw new ArgumentNullException(nameof(chord));
3737
}
3838

39-
int start = 0;
40-
var first = GetOneKey(chord, ref start);
39+
var keyChord = new List<ConsoleKeyInfo>(2);
4140

42-
if (start >= chord.Length)
43-
return new [] { first };
41+
int index = 0;
4442

45-
if (chord[start++] != ',')
46-
throw CantConvert(PSReadLineResources.InvalidSequence, chord);
43+
while (true)
44+
{
45+
keyChord.Add(GetOneKey(chord, ref index));
46+
47+
if (index >= chord.Length)
48+
break;
4749

48-
var second = GetOneKey(chord, ref start);
49-
if (start < chord.Length)
50-
throw CantConvert(PSReadLineResources.InvalidSequence, chord);
50+
if (chord[index++] != ',')
51+
throw CantConvert(PSReadLineResources.InvalidSequence, chord);
52+
}
5153

52-
return new [] { first, second };
54+
return keyChord.ToArray();
5355
}
5456

5557
private static ConsoleKeyInfo GetOneKey(string chord, ref int start)

PSReadLine/History.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,13 @@ private void InteractiveHistorySearchLoop(int direction)
11711171
var toMatch = new StringBuilder(64);
11721172
while (true)
11731173
{
1174+
Action<ConsoleKeyInfo?, object> function = null;
1175+
11741176
var key = ReadKey();
1175-
_dispatchTable.TryGetValue(key, out var handler);
1176-
var function = handler?.Action;
1177+
_dispatchTable.TryGetValue(key, out var handlerOrChordDispatchTable);
1178+
if (handlerOrChordDispatchTable.TryGetKeyHandler(out var handler))
1179+
function = handler.Action;
1180+
11771181
if (function == ReverseSearchHistory)
11781182
{
11791183
UpdateHistoryDuringInteractiveSearch(toMatch.ToString(), -1, ref searchFromPoint);

PSReadLine/KeyBindings.cs

+229-68
Large diffs are not rendered by default.

PSReadLine/KeyBindings.vi.cs

+234-257
Large diffs are not rendered by default.

PSReadLine/Movement.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ private static bool CheckIsBound(Action<ConsoleKeyInfo?, object> action)
370370
{
371371
foreach (var entry in _singleton._dispatchTable)
372372
{
373-
if (entry.Value.Action == action)
373+
if (entry.Value.TryGetKeyHandler(out var handler) && handler.Action == action)
374374
return true;
375375
}
376376
return false;

0 commit comments

Comments
 (0)