Skip to content

Commit

Permalink
Merge pull request #3849 from BDisp/v2_3847_tabview-focus-fix
Browse files Browse the repository at this point in the history
Fixes #3847. TabView changes focus to Tab on Layout.
  • Loading branch information
tig authored Nov 26, 2024
2 parents 92c546e + 37bb43a commit f6db2fc
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 105 deletions.
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

0 comments on commit f6db2fc

Please sign in to comment.