瀏覽代碼

Fixed colorpicker

Tig 11 月之前
父節點
當前提交
5b8ff59a57
共有 2 個文件被更改,包括 11 次插入7 次删除
  1. 5 2
      Terminal.Gui/View/View.Navigation.cs
  2. 6 5
      UnitTests/Views/ColorPickerTests.cs

+ 5 - 2
Terminal.Gui/View/View.Navigation.cs

@@ -426,12 +426,15 @@ public partial class View // Focus and cross-view navigation management (TabStop
         }
         else
         {
-            if (SuperView is { })
+            // We're moving beyond the last subview
+
+            // Determine if focus should remain in this focus chain, or move to the superview's focus chain
+            if (SuperView is { } && SuperView.GetScopedTabIndexes (direction, behavior).Length > 1)
             {
+                // Our superview has an focusable subview in addition to us
                 return false;
             }
 
-            // We're moving beyond the last subview
             // If our superview 
             //if (behavior == TabBehavior.TabGroup && behavior == TabStop && SuperView?.TabStop == TabBehavior.TabGroup)
             {

+ 6 - 5
UnitTests/Views/ColorPickerTests.cs

@@ -665,7 +665,7 @@ public class ColorPickerTests
         var name = GetTextField (cp, ColorPickerPart.ColorName);
         var hex = GetTextField (cp, ColorPickerPart.Hex);
 
-        name.RestoreFocus (TabBehavior.TabStop);
+        name.SetFocus ();
 
         Assert.True (name.HasFocus);
         Assert.Same (name, cp.Focused);
@@ -705,7 +705,7 @@ public class ColorPickerTests
         var name = GetTextField (cp, ColorPickerPart.ColorName);
         var hex = GetTextField (cp, ColorPickerPart.Hex);
 
-        hex.RestoreFocus (TabBehavior.TabStop);
+        hex.SetFocus ();
 
         Assert.True (hex.HasFocus);
         Assert.Same (hex, cp.Focused);
@@ -730,7 +730,9 @@ public class ColorPickerTests
 
         Application.OnKeyDown ('4');
 
-        // Tab out of the text field
+        Assert.True (hex.HasFocus);
+
+        // Tab out of the hex field - should wrap to first focusable subview 
         Application.OnKeyDown (Key.Tab);
         Assert.False (hex.HasFocus);
         Assert.NotSame (hex, cp.Focused);
@@ -759,11 +761,10 @@ public class ColorPickerTests
 
         Application.Current = new Toplevel () { Width = 20, Height = 5 };
         Application.Current.Add (cp);
-        Application.Current.RestoreFocus (null);
 
         Application.Current.LayoutSubviews ();
+        Application.Current.SetFocus ();
 
-        Application.Current.RestoreFocus (null);
         return cp;
     }
 }