Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3847. TabView changes focus to Tab on Layout. #3849

Merged
merged 9 commits into from
Nov 26, 2024
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#nullable enable
namespace Terminal.Gui;

internal class TabRowView : View
internal class TabRow : View
{
private readonly TabView _host;
private readonly View _leftScrollIndicator;
private readonly View _rightScrollIndicator;

public TabRowView (TabView host)
public TabRow (TabView host)
{
_host = host;
Id = "tabRowView";
Id = "tabRow";

CanFocus = true;
TabStop = TabBehavior.TabGroup;
Width = Dim.Fill ();

_rightScrollIndicator = new View
Expand Down Expand Up @@ -59,25 +60,25 @@ protected override bool OnMouseEvent (MouseEventArgs me)
}
}

if (!me.IsSingleDoubleOrTripleClicked)
if (me.IsWheel && !HasFocus && CanFocus)
{
return false;
SetFocus ();
}

if (!HasFocus && CanFocus)
if (me is { IsSingleDoubleOrTripleClicked: false, IsWheel: false })
{
SetFocus ();
return false;
}

if (me.IsSingleDoubleOrTripleClicked)
if (me.IsSingleDoubleOrTripleClicked || me.IsWheel)
{
var scrollIndicatorHit = 0;

if (me.View is { Id: "rightScrollIndicator" })
if (me.View is { Id: "rightScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledDown) || me.Flags.HasFlag (MouseFlags.WheeledRight))
{
scrollIndicatorHit = 1;
}
else if (me.View is { Id: "leftScrollIndicator" })
else if (me.View is { Id: "leftScrollIndicator" } || me.Flags.HasFlag (MouseFlags.WheeledUp) || me.Flags.HasFlag (MouseFlags.WheeledLeft))
{
scrollIndicatorHit = -1;
}
Expand Down
8 changes: 6 additions & 2 deletions Terminal.Gui/Views/TabView/TabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TabView : View
private readonly List<Tab> _tabs = new ();

/// <summary>This sub view is the 2 or 3 line control that represents the actual tabs themselves.</summary>
private readonly TabRowView _tabsBar;
private readonly TabRow _tabsBar;

private Tab? _selectedTab;

Expand All @@ -28,7 +28,7 @@ public TabView ()
{
CanFocus = true;
TabStop = TabBehavior.TabStop; // Because TabView has focusable subviews, it must be a TabGroup
_tabsBar = new TabRowView (this);
_tabsBar = new TabRow (this);
_containerView = new ();
ApplyStyleChanges ();

Expand Down Expand Up @@ -518,6 +518,10 @@ internal IEnumerable<Tab> CalculateViewport (Rectangle bounds)
{
SelectedTab?.SetFocus ();
}
else
{
SelectedTab?.View?.SetFocus ();
}
}

/// <summary>
Expand Down
Loading