Browse Source

RestoreFocus is internal

Tig 11 months ago
parent
commit
760455806c

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

@@ -87,7 +87,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
         }
         }
 
 
         int focusedIndex = index.IndexOf (Focused); // Will return -1 if Focused can't be found or is null
         int focusedIndex = index.IndexOf (Focused); // Will return -1 if Focused can't be found or is null
-        var next = 0;
+        int next = 0;
 
 
         if (focusedIndex < index.Length - 1)
         if (focusedIndex < index.Length - 1)
         {
         {
@@ -255,7 +255,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
     /// <returns>
     /// <returns>
     ///     Returns true if focus was restored to a subview, false otherwise.
     ///     Returns true if focus was restored to a subview, false otherwise.
     /// </returns>
     /// </returns>
-    internal bool RestoreFocus (TabBehavior? behavior)
+    internal bool RestoreFocus ()
     {
     {
         if (Focused is null && _subviews?.Count > 0)
         if (Focused is null && _subviews?.Count > 0)
         {
         {
@@ -432,7 +432,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
         if (!traversingUp)
         if (!traversingUp)
         {
         {
             // Restore focus to the previously most focused subview in the subview-hierarchy
             // Restore focus to the previously most focused subview in the subview-hierarchy
-            if (!RestoreFocus (TabStop))
+            if (!RestoreFocus ())
             {
             {
                 // Couldn't restore focus, so use Advance to navigate to the next focusable subview
                 // Couldn't restore focus, so use Advance to navigate to the next focusable subview
                 if (!AdvanceFocus (NavigationDirection.Forward, null))
                 if (!AdvanceFocus (NavigationDirection.Forward, null))
@@ -560,7 +560,7 @@ public partial class View // Focus and cross-view navigation management (TabStop
                 // Temporarily ensure this view can't get focus
                 // Temporarily ensure this view can't get focus
                 bool prevCanFocus = _canFocus;
                 bool prevCanFocus = _canFocus;
                 _canFocus = false;
                 _canFocus = false;
-                bool restoredFocus = Application.Current!.RestoreFocus (null);
+                bool restoredFocus = Application.Current!.RestoreFocus ();
                 _canFocus = prevCanFocus;
                 _canFocus = prevCanFocus;
 
 
                 if (restoredFocus)
                 if (restoredFocus)

+ 5 - 4
Terminal.Gui/Views/Toplevel.cs

@@ -376,10 +376,11 @@ public partial class Toplevel : View
     {
     {
         if (!IsOverlappedContainer)
         if (!IsOverlappedContainer)
         {
         {
-            if (Focused is null)
-            {
-                RestoreFocus (null);
-            }
+            //if (Focused is null)
+            //{
+            //    // 
+            //    RestoreFocus ();
+            //}
 
 
             return null;
             return null;
         }
         }

+ 4 - 4
UnitTests/View/Navigation/RestoreFocusTests.cs

@@ -54,7 +54,7 @@ public class RestoreFocusTests () : TestsAllViews
         Assert.False (subViewSubView2.HasFocus);
         Assert.False (subViewSubView2.HasFocus);
         Assert.False (subViewSubView3.HasFocus);
         Assert.False (subViewSubView3.HasFocus);
 
 
-        view.RestoreFocus (view.TabStop);
+        view.RestoreFocus ();
         Assert.True (view.HasFocus);
         Assert.True (view.HasFocus);
         Assert.True (subView.HasFocus);
         Assert.True (subView.HasFocus);
         Assert.Equal (subView, view.Focused);
         Assert.Equal (subView, view.Focused);
@@ -77,7 +77,7 @@ public class RestoreFocusTests () : TestsAllViews
         Assert.False (subViewSubView2.HasFocus);
         Assert.False (subViewSubView2.HasFocus);
         Assert.False (subViewSubView3.HasFocus);
         Assert.False (subViewSubView3.HasFocus);
 
 
-        view.RestoreFocus (view.TabStop);
+        view.RestoreFocus ();
         Assert.True (subView.HasFocus);
         Assert.True (subView.HasFocus);
         Assert.Equal (subView, view.Focused);
         Assert.Equal (subView, view.Focused);
         Assert.True (subViewSubView2.HasFocus);
         Assert.True (subViewSubView2.HasFocus);
@@ -155,7 +155,7 @@ public class RestoreFocusTests () : TestsAllViews
         top.HasFocus = false;
         top.HasFocus = false;
         Assert.False (top.HasFocus);
         Assert.False (top.HasFocus);
 
 
-        top.RestoreFocus (null);
+        top.RestoreFocus ();
         Assert.True (top.HasFocus);
         Assert.True (top.HasFocus);
         Assert.Equal (tabGroup2, top.Focused);
         Assert.Equal (tabGroup2, top.Focused);
         Assert.Equal (tabGroup2SubView1, tabGroup2.Focused);
         Assert.Equal (tabGroup2SubView1, tabGroup2.Focused);
@@ -163,7 +163,7 @@ public class RestoreFocusTests () : TestsAllViews
         top.HasFocus = false;
         top.HasFocus = false;
         Assert.False (top.HasFocus);
         Assert.False (top.HasFocus);
 
 
-        top.RestoreFocus (TabBehavior.TabGroup);
+        top.RestoreFocus ();
         Assert.True (top.HasFocus);
         Assert.True (top.HasFocus);
         Assert.Equal (tabGroup2, top.Focused);
         Assert.Equal (tabGroup2, top.Focused);
         Assert.Equal (tabGroup2SubView1, tabGroup2.Focused);
         Assert.Equal (tabGroup2SubView1, tabGroup2.Focused);

+ 4 - 4
UnitTests/Views/TextFieldTests.cs

@@ -78,7 +78,7 @@ public class TextFieldTests (ITestOutputHelper output)
     public void Cancel_TextChanging_ThenBackspace ()
     public void Cancel_TextChanging_ThenBackspace ()
     {
     {
         var tf = new TextField ();
         var tf = new TextField ();
-        tf.RestoreFocus (null);
+        tf.SetFocus ();
         tf.NewKeyDownEvent (Key.A.WithShift);
         tf.NewKeyDownEvent (Key.A.WithShift);
         Assert.Equal ("A", tf.Text);
         Assert.Equal ("A", tf.Text);
 
 
@@ -908,7 +908,7 @@ public class TextFieldTests (ITestOutputHelper output)
         var tf = new TextField { Width = 10 };
         var tf = new TextField { Width = 10 };
         top.Add (tf);
         top.Add (tf);
 
 
-        Exception exception = Record.Exception (() => tf.SetFocus());
+        Exception exception = Record.Exception (() => tf.SetFocus ());
         Assert.Null (exception);
         Assert.Null (exception);
     }
     }
 
 
@@ -928,7 +928,7 @@ public class TextFieldTests (ITestOutputHelper output)
     public void Backspace_From_End ()
     public void Backspace_From_End ()
     {
     {
         var tf = new TextField { Text = "ABC" };
         var tf = new TextField { Text = "ABC" };
-        tf.RestoreFocus (null);
+        tf.SetFocus ();
         Assert.Equal ("ABC", tf.Text);
         Assert.Equal ("ABC", tf.Text);
         tf.BeginInit ();
         tf.BeginInit ();
         tf.EndInit ();
         tf.EndInit ();
@@ -955,7 +955,7 @@ public class TextFieldTests (ITestOutputHelper output)
     public void Backspace_From_Middle ()
     public void Backspace_From_Middle ()
     {
     {
         var tf = new TextField { Text = "ABC" };
         var tf = new TextField { Text = "ABC" };
-        tf.RestoreFocus (null);
+        tf.SetFocus ();
         tf.CursorPosition = 2;
         tf.CursorPosition = 2;
         Assert.Equal ("ABC", tf.Text);
         Assert.Equal ("ABC", tf.Text);