From 2a12c4bbd75e04f86719c5941d951af7aa58c909 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 14 Apr 2022 11:05:21 -0700 Subject: [PATCH] With a fix in PSReadLine, we don't have to return a "null" key press Which wasn't reliable anyway, because it could be translated to different things depending on the system and encodings in use. PSReadLine now just discards any key input after cancellation. This requires an update to PSReadLine v2.2.3. --- modules.json | 2 +- .../Services/PowerShell/Host/PsesInternalHost.cs | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/modules.json b/modules.json index 1f17d7faa..a3000fab8 100644 --- a/modules.json +++ b/modules.json @@ -6,6 +6,6 @@ "Version": "1.1.3" }, "PSReadLine": { - "Version": "2.2.2" + "Version": "2.2.3" } } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index e0d2d15d3..8697f45ab 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -1022,13 +1022,6 @@ private void OnCancelKeyPress(object sender, ConsoleCancelEventArgs args) } } - private static readonly ConsoleKeyInfo s_nullKeyInfo = new( - keyChar: ' ', - ConsoleKey.DownArrow, - shift: false, - alt: false, - control: false); - private ConsoleKeyInfo ReadKey(bool intercept) { // PSRL doesn't tell us when CtrlC was sent. @@ -1047,11 +1040,7 @@ private ConsoleKeyInfo ReadKey(bool intercept) // TODO: We may want to allow users of PSES to override this method call. _lastKey = System.Console.ReadKey(intercept); - - // TODO: After fixing PSReadLine so that when canceled it doesn't read a key, we can - // stop using s_nullKeyInfo (which is a down arrow so we don't change the buffer - // content). Without this, the sent key press is translated to an @ symbol. - return _readKeyCancellationToken.IsCancellationRequested ? s_nullKeyInfo : _lastKey.Value; + return _lastKey.Value; } internal ConsoleKeyInfo ReadKey(bool intercept, CancellationToken cancellationToken)