Bläddra i källkod

Fixes #3771. TextView doesn't consider no-printable rune in draw and cursor position.

BDisp 10 månader sedan
förälder
incheckning
6a6c210d9b
2 ändrade filer med 21 tillägg och 0 borttagningar
  1. 7 0
      Terminal.Gui/Views/TextView.cs
  2. 14 0
      UnitTests/Views/TextViewTests.cs

+ 7 - 0
Terminal.Gui/Views/TextView.cs

@@ -3591,6 +3591,8 @@ public class TextView : View
                 else
                 {
                     AddRune (col, row, rune);
+                    // Ensures that cols less than 0 to be 1 because it will be converted to a printable rune
+                    cols = Math.Max (cols, 1);
                 }
 
                 if (!TextModel.SetCol (ref col, viewport.Right, cols))
@@ -3802,6 +3804,11 @@ public class TextView : View
                 {
                     cols += TabWidth + 1;
                 }
+                else
+                {
+                    // Ensures that cols less than 0 to be 1 because it will be converted to a printable rune
+                    cols = Math.Max (cols, 1);
+                }
 
                 if (!TextModel.SetCol (ref col, Viewport.Width, cols))
                 {

+ 14 - 0
UnitTests/Views/TextViewTests.cs

@@ -8660,4 +8660,18 @@ line.
         Assert.True (t.Visible);
         Assert.False (t.Autocomplete.Visible);
     }
+
+    [Fact]
+    [AutoInitShutdown]
+    public void Draw_Esc_Rune ()
+    {
+        var tv = new TextView { Width = 5, Height = 1, Text = "\u001b" };
+        tv.BeginInit ();
+        tv.EndInit ();
+        tv.Draw ();
+
+        TestHelpers.AssertDriverContentsWithFrameAre ("\u241b", _output);
+
+        tv.Dispose ();
+    }
 }