Skip to content

Commit 2bb057e

Browse files
committed
Add wheel feature.
1 parent f2ffae1 commit 2bb057e

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

Terminal.Gui/Views/TabView/TabRowView.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ protected override bool OnMouseEvent (MouseEventArgs me)
6565
SetFocus ();
6666
}
6767

68-
if (!me.IsSingleDoubleOrTripleClicked)
68+
if (me is { IsSingleDoubleOrTripleClicked: false, IsWheel: false })
6969
{
7070
return false;
7171
}
7272

73-
if (me.IsSingleDoubleOrTripleClicked)
73+
if (me.IsSingleDoubleOrTripleClicked || me.IsWheel)
7474
{
7575
var scrollIndicatorHit = 0;
7676

77-
if (me.View is { Id: "rightScrollIndicator" })
77+
if (me.View is { Id: "rightScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight))
7878
{
7979
scrollIndicatorHit = 1;
8080
}
81-
else if (me.View is { Id: "leftScrollIndicator" })
81+
else if (me.View is { Id: "leftScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft))
8282
{
8383
scrollIndicatorHit = -1;
8484
}

UnitTests/Views/TabViewTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,35 @@ public void Tab_Get_Focus_By_Press_F6 ()
14901490
top.Dispose ();
14911491
}
14921492

1493+
[Fact]
1494+
[SetupFakeDriver]
1495+
public void Mouse_Wheel_Changes_Tab ()
1496+
{
1497+
TabView tv = GetTabView (out Tab tab1, out Tab tab2);
1498+
1499+
tv.Width = 20;
1500+
tv.Height = 5;
1501+
1502+
Toplevel top = new ();
1503+
top.Add (tv);
1504+
Application.Begin (top);
1505+
1506+
Assert.False (tab1.HasFocus);
1507+
1508+
Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledDown });
1509+
Assert.True (tab2.HasFocus);
1510+
1511+
Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledUp });
1512+
Assert.True (tab1.HasFocus);
1513+
1514+
Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledRight });
1515+
Assert.True (tab2.HasFocus);
1516+
1517+
Application.RaiseMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.WheeledLeft });
1518+
Assert.True (tab1.HasFocus);
1519+
top.Dispose ();
1520+
}
1521+
14931522
private TabView GetTabView () { return GetTabView (out _, out _); }
14941523

14951524
private TabView GetTabView (out Tab tab1, out Tab tab2, bool initFakeDriver = true)

0 commit comments

Comments
 (0)