diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index e140be4c3..0c32b2f59 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -304,6 +304,7 @@ public class TextFormatter { if (isVertical) { + // BUGBUG: This works with a very limited set of wide-char scenarios. int runesWidth = runes.Length == 0 ? 0 : runes.Max (r => GetRuneWidth (r, TabWidth)); x = screen.Left + (screen.Width - _lines.Count - 1) + (runesWidth + line); CursorPosition = screen.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0); @@ -319,8 +320,11 @@ public class TextFormatter { if (isVertical) { - int runesWidth = runes.Length == 0 ? 0 : runes.Max (r => GetRuneWidth (r, TabWidth)); - x = screen.Left + runesWidth + line - 1; + // BUGBUG: This works only if a) all lines have only single-wide chars and b) only one line has wide chars + int runesWidth = line > 0 + ? GetColumnsRequiredForVerticalText (linesFormatted, 0, line, TabWidth) + : 0; + x = screen.Left + runesWidth; } else { @@ -333,8 +337,9 @@ public class TextFormatter { if (isVertical) { - int runesWidth = runes.Length == 0 ? 0 : runes.Max (r => GetRuneWidth (r, TabWidth)); - x = screen.Left + (screen.Width / 2) - (_lines.Count / 2) + (runesWidth + line - 1); + // BUGBUG: This works with a very limited set of wide-char scenarios. + int runesWidth = GetColumnsRequiredForVerticalText (linesFormatted, tabWidth: TabWidth); + x = screen.Left + line + (screen.Width - runesWidth) / 2; CursorPosition = (screen.Width - runesWidth) / 2 + (_hotKeyPos > -1 ? _hotKeyPos : 0); } diff --git a/UnitTests/Text/TextFormatterTests.cs b/UnitTests/Text/TextFormatterTests.cs index aa2bf175c..b9beb0666 100644 --- a/UnitTests/Text/TextFormatterTests.cs +++ b/UnitTests/Text/TextFormatterTests.cs @@ -3482,7 +3482,7 @@ ssb [InlineData ("A", 2, false, "A")] [InlineData ("AB12", 5, false, "AB12")] [InlineData ("AB\n12", 5, false, "A1\nB2")] - [InlineData ("デモエ", 1, false, "")] + [InlineData ("", 1, false, "")] public void Draw_Vertical_TopBottom_LeftRight (string text, int width, bool autoSize, string expectedText) {