소스 검색

Fixed Combobox

Tig 11 달 전
부모
커밋
755c0afe7f
3개의 변경된 파일22개의 추가작업 그리고 8개의 파일을 삭제
  1. 1 1
      Terminal.Gui/View/View.Navigation.cs
  2. 3 2
      Terminal.Gui/Views/ComboBox.cs
  3. 18 5
      UnitTests/Views/ComboBoxTests.cs

+ 1 - 1
Terminal.Gui/View/View.Navigation.cs

@@ -123,7 +123,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
             }
 
             // Couldn't restore focus, so use Advance to navigate to the next focusable subview
-            if (AdvanceFocus (NavigationDirection.Forward, null))
+            if (AdvanceFocus (NavigationDirection.Forward, TabBehavior.TabStop))
             {
                 // A subview was focused. We're done because the subview has focus and it recursed up the superview hierarchy.
                 return true;

+ 3 - 2
Terminal.Gui/Views/ComboBox.cs

@@ -302,14 +302,15 @@ public class ComboBox : View, IDesignable
     /// <inheritdoc/>
     protected override bool OnHasFocusChanging (View view)
     {
+        bool cancel = false;
         if (!_search.HasFocus && !_listview.HasFocus)
         {
-            _search.SetFocus ();
+            cancel = _search.SetFocus ();
         }
 
         _search.CursorPosition = _search.Text.GetRuneCount ();
 
-        return false; // Don't cancel the focus switch
+        return cancel; 
     }
 
     /// <summary>Virtual method which invokes the <see cref="Expanded"/> event.</summary>

+ 18 - 5
UnitTests/Views/ComboBoxTests.cs

@@ -500,9 +500,14 @@ public class ComboBoxTests (ITestOutputHelper output)
         cb.SetSource (["One", "Two", "Three"]);
         cb.OpenSelectedItem += (s, e) => selected = e.Value.ToString ();
         var top = new Toplevel ();
-        top.Add (cb);
+
+        View otherView = new View () { CanFocus = true };
+
+        top.Add (otherView, cb);
         Application.Begin (top);
 
+        Assert.False (cb.HasFocus);
+
         Assert.True (cb.HideDropdownListOnClick);
         Assert.False (cb.IsShow);
         Assert.Equal (-1, cb.SelectedItem);
@@ -819,7 +824,6 @@ Three ",
 
         var otherView = new View () { CanFocus = true };
         top.Add (otherView);
-        //        top.FocusFirst (null);
         Application.Begin (top);
 
         Assert.True (cb.HasFocus);
@@ -839,6 +843,7 @@ Three ",
         Assert.False (Application.OnKeyDown (Key.Enter));
         Assert.True (Application.OnKeyDown (Key.F4)); // with no source also expand empty
         Assert.True (cb.IsShow);
+
         Assert.Equal (-1, cb.SelectedItem);
         cb.SetSource (source);
         cb.Text = "";
@@ -856,6 +861,7 @@ Three ",
         Assert.False (cb.IsShow);
         Assert.True (cb.HasFocus);
         cb.Expand ();
+
         Assert.True (cb.IsShow);
         Assert.Equal (0, cb.SelectedItem);
         Assert.Equal ("One", cb.Text);
@@ -884,6 +890,7 @@ Three ",
         Assert.Equal (0, cb.SelectedItem);
         Assert.Equal ("One", cb.Text);
 
+        cb.Draw ();
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 One      ▼
@@ -896,8 +903,9 @@ One
         Assert.True (cb.IsShow);
         Assert.Equal (1, cb.SelectedItem);
         Assert.Equal ("Two", cb.Text);
-        Application.Begin (top);
+//        Application.Begin (top);
 
+        cb.Draw ();
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 Two      ▼
@@ -910,8 +918,9 @@ Two
         Assert.True (cb.IsShow);
         Assert.Equal (2, cb.SelectedItem);
         Assert.Equal ("Three", cb.Text);
-        Application.Begin (top);
+        //Application.Begin (top);
 
+        cb.Draw ();
         TestHelpers.AssertDriverContentsWithFrameAre (
                                                       @"
 Three    ▼
@@ -974,11 +983,14 @@ Three
         top.Dispose ();
     }
 
-    [Fact (Skip = "BUGBUG: New focus stuff broke. Fix later.")]
+    [Fact]
     public void Source_Equal_Null_Or_Count_Equal_Zero_Sets_SelectedItem_Equal_To_Minus_One ()
     {
+        Application.Navigation = new ();
         var cb = new ComboBox ();
         var top = new Toplevel ();
+        Application.Current = top;
+
         top.Add (cb);
         top.FocusDeepest (NavigationDirection.Forward, null);
         Assert.Null (cb.Source);
@@ -1015,5 +1027,6 @@ Three
         Assert.Equal (0, cb.Source.Count);
         Assert.Equal (-1, cb.SelectedItem);
         Assert.Equal ("", cb.Text);
+        Application.ResetState ();
     }
 }