Browse Source

Improving Application.Navigation

Tig 11 months ago
parent
commit
f0508b9831
3 changed files with 14 additions and 2 deletions
  1. 12 1
      UnitTests/Views/ColorPickerTests.cs
  2. 1 0
      UnitTests/Views/LabelTests.cs
  3. 1 1
      docfx/docs/navigation.md

+ 12 - 1
UnitTests/Views/ColorPickerTests.cs

@@ -1,4 +1,5 @@
-using Xunit.Abstractions;
+using System.Reflection.Emit;
+using Xunit.Abstractions;
 using Color = Terminal.Gui.Color;
 
 namespace Terminal.Gui.ViewsTests;
@@ -692,6 +693,10 @@ public class ColorPickerTests
     public void ColorPicker_TabCompleteColorName ()
     {
         var cp = GetColorPicker (ColorModel.RGB, true, true);
+        Application.Navigation = new ();
+        Application.Current = new ();
+        Application.Current.Add (cp);
+
         cp.Draw ();
 
         var r = GetColorBar (cp, ColorPickerPart.Bar1);
@@ -728,6 +733,7 @@ public class ColorPickerTests
         Assert.Equal ("#7FFFD4", hex.Text);
 
         Application.Current?.Dispose ();
+        Application.ResetState ();
     }
 
     [Fact]
@@ -735,6 +741,10 @@ public class ColorPickerTests
     public void ColorPicker_EnterHexFor_ColorName ()
     {
         var cp = GetColorPicker (ColorModel.RGB, true, true);
+        Application.Navigation = new ();
+        Application.Current = new ();
+        Application.Current.Add (cp);
+
         cp.Draw ();
 
         var name = GetTextField (cp, ColorPickerPart.ColorName);
@@ -777,6 +787,7 @@ public class ColorPickerTests
         Assert.Equal ("Aquamarine", name.Text);
 
         Application.Current?.Dispose ();
+        Application.ResetState ();
     }
 
     [Fact]

+ 1 - 0
UnitTests/Views/LabelTests.cs

@@ -1321,6 +1321,7 @@ e
     {
         Label label = new () { Text = "label" };
         View view = new () { Text = "view", CanFocus = true };
+        Application.Navigation = new ();
         Application.Current = new ();
         Application.Current.Add (label, view);
 

+ 1 - 1
docfx/docs/navigation.md

@@ -98,7 +98,7 @@ Causes the focus to advance (forward or backwards) to the next View in the appli
 The implementation is simple:
 
 ```cs
-return Application.GetFocused()?.AdvanceFocus (direction, behavior) ?? false;
+return Application.Current?.AdvanceFocus (direction, behavior);
 ```
 
 This method is called from the `Command` handlers bound to the application-scoped keybindings created during `Application.Init`. It is `public` as a convenience.