Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PSReadLine/KeyBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ void SetDefaultWindowsBindings()
{ Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") },
{ Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") },
{ Keys.CtrlPageDown, MakeKeyHandler(ScrollDisplayDownLine, "ScrollDisplayDownLine") },
{ Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") },
};

// Some bindings are not available on certain platforms
Expand Down Expand Up @@ -334,6 +337,9 @@ void SetDefaultEmacsBindings()
{ Keys.CtrlAltY, MakeKeyHandler(YankNthArg, "YankNthArg") },
{ Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") },
{ Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") },
{ Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") },
};

// Some bindings are not available on certain platforms
Expand Down
10 changes: 8 additions & 2 deletions PSReadLine/KeyBindings.vi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ private void SetDefaultViBindings()
{ Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward,"CharacterSearchBackward") },
{ Keys.CtrlAltQuestion, MakeKeyHandler(ShowKeyBindings, "ShowKeyBindings") },
{ Keys.CtrlR, MakeKeyHandler(ViSearchHistoryBackward,"ViSearchHistoryBackward") },
{ Keys.CtrlS, MakeKeyHandler(SearchForward, "SearchForward") }
{ Keys.CtrlS, MakeKeyHandler(SearchForward, "SearchForward") },
{ Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") },
};

// Some bindings are not available on certain platforms
Expand Down Expand Up @@ -205,7 +208,10 @@ private void SetDefaultViBindings()
{ Keys.Minus, MakeKeyHandler(PreviousHistory, "PreviousHistory") },
{ Keys.Period, MakeKeyHandler(RepeatLastCommand, "RepeatLastCommand") },
{ Keys.Semicolon, MakeKeyHandler(RepeatLastCharSearch, "RepeatLastCharSearch") },
{ Keys.Comma, MakeKeyHandler(RepeatLastCharSearchBackwards, "RepeatLastCharSearchBackwards") }
{ Keys.Comma, MakeKeyHandler(RepeatLastCharSearchBackwards, "RepeatLastCharSearchBackwards") },
{ Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") },
{ Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") },
};

// Some bindings are not available on certain platforms
Expand Down
43 changes: 6 additions & 37 deletions PSReadLine/Keys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ static ConsoleKeyInfo CtrlAlt(char c)
public static ConsoleKeyInfo CtrlAltRBracket = CtrlAlt(']');
public static ConsoleKeyInfo CtrlAltQuestion = CtrlAlt('?');

public static ConsoleKeyInfo VolumeUp = Key(ConsoleKey.VolumeUp);
public static ConsoleKeyInfo VolumeDown = Key(ConsoleKey.VolumeDown);
public static ConsoleKeyInfo VolumeMute = Key(ConsoleKey.VolumeMute);

[DllImport("user32.dll")]
public static extern int VkKeyScan(short wAsciiVal);
Expand Down Expand Up @@ -469,6 +472,9 @@ internal static bool IgnoreKeyChar(this ConsoleKeyInfo key)
case ConsoleKey.RightArrow:
case ConsoleKey.Tab:
case ConsoleKey.UpArrow:
case ConsoleKey.VolumeUp:
case ConsoleKey.VolumeDown:
case ConsoleKey.VolumeMute:
return true;
}

Expand Down Expand Up @@ -560,43 +566,6 @@ internal static int GetNormalizedHashCode(this ConsoleKeyInfo obj)
return unchecked(((h1 << 5) + h1) ^ h2);
}

internal static bool ShouldInsert(this ConsoleKeyInfo key)
{
var keyChar = key.KeyChar;
if (keyChar == '\0') return false;
foreach (char c in " `~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?") {
// we always want to insert chars essential to the PowerShell experience
if (keyChar == c) { return true; }
}
if (key.Modifiers != 0)
{
// We want to ignore control sequences - but distinguishing a control sequence
// isn't as simple as it could be because we will get inconsistent modifiers
// depending on the OS or keyboard layout.
//
// Windows will give us the key state even if we didn't care, e.g. it's normal
// to see Alt+Control (AltGr) on a Spanish, French, or German keyboard for many normal
// characters. So we just ask the OS what mods to expect for a given key.
// On non-Windows - anything but Shift is assumed to be a control sequence.
ConsoleModifiers expectedMods = default(ConsoleModifiers);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var keyWithMods = WindowsKeyScan(key.KeyChar);
if (keyWithMods.HasValue)
{
expectedMods = keyWithMods.Value.Modifiers;
}
}
else
{
expectedMods = key.Modifiers & ConsoleModifiers.Shift;
}
return key.Modifiers == expectedMods;
}

return true;
}

internal static bool IsUnmodifiedChar(this ConsoleKeyInfo key, char c)
{
return key.KeyChar == c &&
Expand Down
7 changes: 6 additions & 1 deletion PSReadLine/ReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ void ProcessOneKey(ConsoleKeyInfo key, Dictionary<ConsoleKeyInfo, KeyHandler> di
handler.Action(key, arg);
}
}
else if (!ignoreIfNoAction && key.ShouldInsert())
else if (!ignoreIfNoAction)
{
SelfInsert(key, arg);
}
Expand Down Expand Up @@ -848,6 +848,11 @@ private static void Chord(ConsoleKeyInfo? key = null, object arg = null)
}
}

[SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
private static void Ignore(ConsoleKeyInfo? key = null, object arg = null)
{
}

/// <summary>
/// Abort current action, e.g. incremental history search.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion PSReadLine/Replace.vi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static void ViReplaceUntilEsc(ConsoleKeyInfo? key, object arg)
_singleton.Render();
}
}
else if (nextKey.ShouldInsert())
else
{
if (_singleton._current >= _singleton._buffer.Length)
{
Expand Down