Skip to content

Commit ee24c85

Browse files
authored
Fixes 4110. TextView's IsSelecting property not updating properly on mouse click (#4111)
1 parent 1285912 commit ee24c85

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Terminal.Gui/Views/TextInput/TextView.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,11 @@ protected override bool OnMouseEvent (MouseEventArgs ev)
15391539
{
15401540
_isButtonReleased = false;
15411541

1542+
if (SelectedLength == 0)
1543+
{
1544+
StopSelecting ();
1545+
}
1546+
15421547
return true;
15431548
}
15441549

Tests/UnitTests/Views/TextViewTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9143,5 +9143,36 @@ public void Cell_LoadCells_Without_Scheme_Is_Never_Null ()
91439143
}
91449144
}
91459145

9146+
[Fact]
9147+
[TextViewTestsAutoInitShutdown]
9148+
public void IsSelecting_False_If_SelectedLength_Is_Zero_On_Mouse_Click ()
9149+
{
9150+
_textView.Text = "This is the first line.";
9151+
var top = new Toplevel ();
9152+
top.Add (_textView);
9153+
Application.Begin (top);
9154+
9155+
Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Pressed });
9156+
Assert.Equal (22, _textView.CursorPosition.X);
9157+
Assert.Equal (0, _textView.CursorPosition.Y);
9158+
Assert.Equal (0, _textView.SelectedLength);
9159+
Assert.True (_textView.IsSelecting);
9160+
9161+
Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Released });
9162+
Assert.Equal (22, _textView.CursorPosition.X);
9163+
Assert.Equal (0, _textView.CursorPosition.Y);
9164+
Assert.Equal (0, _textView.SelectedLength);
9165+
Assert.True (_textView.IsSelecting);
9166+
9167+
Application.RaiseMouseEvent (new () { ScreenPosition = new (22, 0), Flags = MouseFlags.Button1Clicked });
9168+
Assert.Equal (22, _textView.CursorPosition.X);
9169+
Assert.Equal (0, _textView.CursorPosition.Y);
9170+
Assert.Equal (0, _textView.SelectedLength);
9171+
Assert.False (_textView.IsSelecting);
9172+
9173+
top.Dispose ();
9174+
Application.Shutdown ();
9175+
}
9176+
91469177
private TextView CreateTextView () { return new () { Width = 30, Height = 10 }; }
91479178
}

0 commit comments

Comments
 (0)