From bb72b44d607a5a2f407e910f6dc21f2a33c1b89a Mon Sep 17 00:00:00 2001 From: tonwin618 Date: Thu, 1 Aug 2024 13:55:09 +0800 Subject: [PATCH] Delete based on character width when pressing Backspace. --- .../Extensions/AnsiConsoleExtensions.Input.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs index 7769e33a5..2d6a4cb0b 100644 --- a/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs +++ b/src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs @@ -52,11 +52,19 @@ internal static async Task ReadLine(this IAnsiConsole console, Style? st { if (text.Length > 0) { + var lastChar = text.Last(); text = text.Substring(0, text.Length - 1); if (mask != null) { - console.Write("\b \b"); + if (UnicodeCalculator.GetWidth(lastChar) == 1) + { + console.Write("\b \b"); + } + else if (UnicodeCalculator.GetWidth(lastChar) == 2) + { + console.Write("\b \b\b \b"); + } } }