Переглянути джерело

Fixes 4110. TextView's IsSelecting property not updating properly on mouse click (#4111)

BDisp 3 місяців тому
батько
коміт
ee24c85894

+ 5 - 0
Terminal.Gui/Views/TextInput/TextView.cs

@@ -1539,6 +1539,11 @@ public class TextView : View, IDesignable
             {
                 _isButtonReleased = false;
 
+                if (SelectedLength == 0)
+                {
+                    StopSelecting ();
+                }
+
                 return true;
             }
 

+ 31 - 0
Tests/UnitTests/Views/TextViewTests.cs

@@ -9143,5 +9143,36 @@ ror       ";
         }
     }
 
+    [Fact]
+    [TextViewTestsAutoInitShutdown]
+    public void IsSelecting_False_If_SelectedLength_Is_Zero_On_Mouse_Click ()
+    {
+        _textView.Text = "This is the first line.";
+        var top = new Toplevel ();
+        top.Add (_textView);
+        Application.Begin (top);
+
+        Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Pressed });
+        Assert.Equal (22, _textView.CursorPosition.X);
+        Assert.Equal (0, _textView.CursorPosition.Y);
+        Assert.Equal (0, _textView.SelectedLength);
+        Assert.True (_textView.IsSelecting);
+
+        Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Released });
+        Assert.Equal (22, _textView.CursorPosition.X);
+        Assert.Equal (0, _textView.CursorPosition.Y);
+        Assert.Equal (0, _textView.SelectedLength);
+        Assert.True (_textView.IsSelecting);
+
+        Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Clicked });
+        Assert.Equal (22, _textView.CursorPosition.X);
+        Assert.Equal (0, _textView.CursorPosition.Y);
+        Assert.Equal (0, _textView.SelectedLength);
+        Assert.False (_textView.IsSelecting);
+
+        top.Dispose ();
+        Application.Shutdown ();
+    }
+
     private TextView CreateTextView () { return new () { Width = 30, Height = 10 }; }
 }