Ver código fonte

Removed coupling between TabStop and CanFocus

Tig 1 ano atrás
pai
commit
e41b24fd40

+ 8 - 13
Terminal.Gui/View/View.Navigation.cs

@@ -766,27 +766,22 @@ public partial class View // Focus and cross-view navigation management (TabStop
     private bool _tabStop = true;
     private bool _tabStop = true;
 
 
     /// <summary>
     /// <summary>
-    ///     Gets or sets whether the view is a stop-point for keyboard navigation between Views. Will be <see langword="true"/>
-    ///     only if <see cref="CanFocus"/> is <see langword="true"/>. Set to <see langword="false"/> to prevent the
-    ///     view from being a stop-point for keyboard navigation.
+    ///     Gets or sets whether the view is a stop-point for keyboard navigation.
     /// </summary>
     /// </summary>
     /// <remarks>
     /// <remarks>
+    /// <para>
+    ///     TabStop is independent of <see cref="CanFocus"/>. If <see cref="CanFocus"/> is <see langword="false"/>, the view will not gain
+    ///     focus even if this property is <see langword="true"/> and vice-versa.
+    /// </para>
+    /// <para>
     ///     The default keyboard navigation keys are <c>Key.Tab</c> and <c>Key>Tab.WithShift</c>. These can be changed by
     ///     The default keyboard navigation keys are <c>Key.Tab</c> and <c>Key>Tab.WithShift</c>. These can be changed by
     ///     modifying the key bindings (see <see cref="KeyBindings.Add(Key, Command[])"/>) of the SuperView.
     ///     modifying the key bindings (see <see cref="KeyBindings.Add(Key, Command[])"/>) of the SuperView.
+    /// </para>
     /// </remarks>
     /// </remarks>
     public bool TabStop
     public bool TabStop
     {
     {
         get => _tabStop;
         get => _tabStop;
-        set
-        {
-            if (_tabStop == value)
-            {
-                return;
-            }
-
-            // BUGBUG: TabStop and CanFocus should be decoupled.
-            _tabStop = CanFocus && value;
-        }
+        set => _tabStop = value;
     }
     }
 
 
     #endregion Tab/Focus Handling
     #endregion Tab/Focus Handling

+ 10 - 0
UnitTests/View/NavigationTests.cs

@@ -1535,6 +1535,16 @@ public class NavigationTests (ITestOutputHelper output) : TestsAllViews
         r.Dispose ();
         r.Dispose ();
     }
     }
 
 
+    [Theory]
+    [CombinatorialData]
+    public void TabStop_And_CanFocus_Are_Decoupled (bool canFocus, bool tabStop)
+    {
+        var view = new View { CanFocus = canFocus, TabStop = tabStop };
+
+        Assert.Equal(canFocus, view.CanFocus);
+        Assert.Equal (tabStop, view.TabStop);
+    }
+
     [Fact (Skip="Causes crash on Ubuntu in Github Action. Bogus test anyway.")]
     [Fact (Skip="Causes crash on Ubuntu in Github Action. Bogus test anyway.")]
     public void WindowDispose_CanFocusProblem ()
     public void WindowDispose_CanFocusProblem ()
     {
     {