From b074114f5f8308e5a4e24534c8e2aa41f2e1ab0e Mon Sep 17 00:00:00 2001 From: Felipe Machado Date: Wed, 25 Sep 2024 16:06:53 -0300 Subject: [PATCH] Solves bug when typing Control+LeftArrow and other similar combinations When typing Control+LeftArrow (and other similar key combinations) the \0 char was being written to the console which was causing havoc in typing. This commit fixes it by preventing writing of the \0 char, but, maybe we should prevent writing non-printable characters altogether --- src/ReadLine/KeyHandler.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ReadLine/KeyHandler.cs b/src/ReadLine/KeyHandler.cs index 046d11d..aad4a4b 100644 --- a/src/ReadLine/KeyHandler.cs +++ b/src/ReadLine/KeyHandler.cs @@ -93,7 +93,12 @@ private void WriteString(string str) WriteChar(character); } - private void WriteChar() => WriteChar(_keyInfo.KeyChar); + private void WriteChar() { + // solves bug when typing things like ControlLeftArrow... + // maybe we should only write printable characters... + if (_keyInfo.KeyChar != '\0') + WriteChar(_keyInfo.KeyChar); + } private void WriteChar(char c) {