Delete based on character width when pressing Backspace.

This commit is contained in:
tonwin618 2024-08-01 13:55:09 +08:00 committed by Patrik Svensson
parent d79e6adc5f
commit bb72b44d60

View File

@ -52,11 +52,19 @@ public static partial class AnsiConsoleExtensions
{
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");
}
}
}