diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs index 55b11fffb..622e6620b 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.PopUp.cs @@ -9,6 +9,7 @@ public abstract partial class PopupAutocomplete { _autoComplete = autoComplete; CanFocus = true; + TabStop = TabBehavior.NoStop; WantMousePositionReports = true; } diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index fe52b9f99..b829dac03 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -48,15 +48,22 @@ public abstract partial class PopupAutocomplete : AutocompleteBase if (_top is { }) { - _top.Initialized += _top_Initialized; + if (_top.IsInitialized) + { + AddPopupToTop (); + } + else + { + _top.Initialized += _top_Initialized; + } _top.Removed += _top_Removed; } } } - private void _top_Initialized (object sender, EventArgs e) + private void _top_Added (object sender, SuperViewChangedEventArgs e) { - AddPopupToTop (); + throw new NotImplementedException (); } /// @@ -544,6 +551,11 @@ public abstract partial class PopupAutocomplete : AutocompleteBase } } + private void _top_Initialized (object sender, EventArgs e) + { + AddPopupToTop (); + } + private void _top_Removed (object sender, SuperViewChangedEventArgs e) { Visible = false; diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 14b62fc63..3eb67ee99 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -43,6 +43,8 @@ public class TextField : View Initialized += TextField_Initialized; + Added += TextField_Added; + // Things this view knows how to do AddCommand ( Command.DeleteCharRight, @@ -134,7 +136,7 @@ public class TextField : View } ); - AddCommand (Command.Left, () => MoveLeft ()); + AddCommand (Command.Left, () => MoveLeft ()); AddCommand ( Command.RightEnd, @@ -405,6 +407,7 @@ public class TextField : View KeyBindings.Add (Key.Enter, Command.Accept); } + /// /// Provides autocomplete context menu based on suggestions at the current cursor position. Configure /// to enable this feature. @@ -1855,6 +1858,15 @@ public class TextField : View ContextMenu.Show (); } + private void TextField_Added (object sender, SuperViewChangedEventArgs e) + { + if (Autocomplete.HostControl is null) + { + Autocomplete.HostControl = this; + Autocomplete.PopupInsideContainer = false; + } + } + private void TextField_Initialized (object sender, EventArgs e) { _cursorPosition = Text.GetRuneCount (); @@ -1864,8 +1876,11 @@ public class TextField : View ScrollOffset = _cursorPosition > Viewport.Width + 1 ? _cursorPosition - Viewport.Width + 1 : 0; } - Autocomplete.HostControl = this; - Autocomplete.PopupInsideContainer = false; + if (Autocomplete.HostControl is null) + { + Autocomplete.HostControl = this; + Autocomplete.PopupInsideContainer = false; + } } } diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 2e9db834e..d68ddaa1c 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -2002,6 +2002,8 @@ public class TextView : View Initialized += TextView_Initialized!; + Added += TextView_Added!; + LayoutComplete += TextView_LayoutComplete; // Things this view knows how to do @@ -2499,6 +2501,11 @@ public class TextView : View KeyBindings.Add ((KeyCode)ContextMenu.Key, KeyBindingScope.HotKey, Command.ShowContextMenu); } + private void TextView_Added1 (object? sender, SuperViewChangedEventArgs e) + { + throw new NotImplementedException (); + } + // BUGBUG: AllowsReturn is mis-named. It should be EnterKeyAccepts. /// /// Gets or sets whether pressing ENTER in a creates a new line of text @@ -6334,9 +6341,21 @@ public class TextView : View return StringExtensions.ToString (encoded); } + private void TextView_Added (object sender, SuperViewChangedEventArgs e) + { + if (Autocomplete.HostControl is null) + { + Autocomplete.HostControl = this; + } + } + + private void TextView_Initialized (object sender, EventArgs e) { - Autocomplete.HostControl = this; + if (Autocomplete.HostControl is null) + { + Autocomplete.HostControl = this; + } OnContentsChanged (); } diff --git a/Terminal.Gui/Views/Tile.cs b/Terminal.Gui/Views/Tile.cs index 5224db8b4..89149f0ec 100644 --- a/Terminal.Gui/Views/Tile.cs +++ b/Terminal.Gui/Views/Tile.cs @@ -14,7 +14,12 @@ public class Tile /// Creates a new instance of the class. public Tile () { - ContentView = new View { Width = Dim.Fill (), Height = Dim.Fill () }; + ContentView = new View + { + Width = Dim.Fill (), + Height = Dim.Fill (), + CanFocus = true + }; #if DEBUG_IDISPOSABLE ContentView.Data = "Tile.ContentView"; #endif diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index 05ae7399f..1d2733bfc 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -10,7 +10,7 @@ public class TileView : View private List _splitterDistances; private List _splitterLines; private List _tiles; - private TileView parentTileView; + private TileView _parentTileView; /// Creates a new instance of the class with 2 tiles (i.e. left and right). public TileView () : this (2) @@ -60,7 +60,7 @@ public class TileView : View /// /// Use to determine if the returned value is the root. /// - public TileView GetParentTileView () { return parentTileView; } + public TileView GetParentTileView () { return _parentTileView; } /// /// Returns the index of the first in which contains @@ -149,7 +149,7 @@ public class TileView : View /// if you want to subdivide a . /// /// - public bool IsRootTileView () { return parentTileView == null; } + public bool IsRootTileView () { return _parentTileView == null; } /// public override void LayoutSubviews () @@ -478,7 +478,7 @@ public class TileView : View var newContainer = new TileView (numberOfPanels) { - Width = Dim.Fill (), Height = Dim.Fill (), parentTileView = this + Width = Dim.Fill (), Height = Dim.Fill (), _parentTileView = this }; // Take everything out of the View we are moving @@ -586,9 +586,9 @@ public class TileView : View { TileView root = this; - while (root.parentTileView is { }) + while (root._parentTileView is { }) { - root = root.parentTileView; + root = root._parentTileView; } return root; diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index 5e1646e18..143e25c8a 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -1379,14 +1379,14 @@ public class ContextMenuTests (ITestOutputHelper output) Assert.True (tf1.HasFocus); Assert.False (tf2.HasFocus); - Assert.Equal (2, win.Subviews.Count); + Assert.Equal (4, win.Subviews.Count); // TF & TV add autocomplete popup's to their superviews. Assert.Null (Application.MouseEnteredView); // Right click on tf2 to open context menu Application.OnMouseEvent (new () { Position = new (1, 3), Flags = MouseFlags.Button3Clicked }); Assert.False (tf1.HasFocus); Assert.False (tf2.HasFocus); - Assert.Equal (3, win.Subviews.Count); + Assert.Equal (5, win.Subviews.Count); Assert.True (tf2.ContextMenu.MenuBar.IsMenuOpen); Assert.True (win.Focused is Menu); Assert.True (Application.MouseGrabView is MenuBar); @@ -1396,7 +1396,7 @@ public class ContextMenuTests (ITestOutputHelper output) Application.OnMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked }); Assert.True (tf1.HasFocus); Assert.False (tf2.HasFocus); - Assert.Equal (2, win.Subviews.Count); + Assert.Equal (4, win.Subviews.Count); // The last context menu bar opened is always preserved Assert.NotNull (tf2.ContextMenu.MenuBar); Assert.Equal (win.Focused, tf1); @@ -1407,7 +1407,7 @@ public class ContextMenuTests (ITestOutputHelper output) Application.OnMouseEvent (new () { Position = new (1, 3), Flags = MouseFlags.Button1Clicked }); Assert.False (tf1.HasFocus); Assert.True (tf2.HasFocus); - Assert.Equal (2, win.Subviews.Count); + Assert.Equal (4, win.Subviews.Count); // The last context menu bar opened is always preserved Assert.NotNull (tf2.ContextMenu.MenuBar); Assert.Equal (win.Focused, tf2); diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index b13ace837..e069a652b 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -1,10 +1,54 @@ -using System.Text; -using Xunit.Abstractions; +using Xunit.Abstractions; namespace Terminal.Gui.ViewsTests; public class MenuBarTests (ITestOutputHelper output) { + [Fact] + [AutoInitShutdown] + public void AddMenuBarItem_RemoveMenuItem_Dynamically () + { + var menuBar = new MenuBar (); + var menuBarItem = new MenuBarItem { Title = "_New" }; + var action = ""; + var menuItem = new MenuItem { Title = "_Item", Action = () => action = "I", Parent = menuBarItem }; + Assert.Equal ("n", menuBarItem.HotKey); + Assert.Equal ("i", menuItem.HotKey); + Assert.Empty (menuBar.Menus); + menuBarItem.AddMenuBarItem (menuItem); + menuBar.Menus = [menuBarItem]; + Assert.Single (menuBar.Menus); + Assert.Single (menuBar.Menus [0].Children); + Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings); + Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings); + + var top = new Toplevel (); + top.Add (menuBar); + Application.Begin (top); + + top.NewKeyDownEvent (Key.N.WithAlt); + Application.MainLoop.RunIteration (); + Assert.True (menuBar.IsMenuOpen); + Assert.Equal ("", action); + + top.NewKeyDownEvent (Key.I); + Application.MainLoop.RunIteration (); + Assert.False (menuBar.IsMenuOpen); + Assert.Equal ("I", action); + + menuItem.RemoveMenuItem (); + Assert.Single (menuBar.Menus); + Assert.Null (menuBar.Menus [0].Children); + Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings); + Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings); + + menuBarItem.RemoveMenuItem (); + Assert.Empty (menuBar.Menus); + Assert.DoesNotContain (Key.N.WithAlt, menuBar.KeyBindings.Bindings); + + top.Dispose (); + } + [Fact] [AutoInitShutdown] public void AllowNullChecked_Get_Set () @@ -155,6 +199,30 @@ public class MenuBarTests (ITestOutputHelper output) top.Dispose (); } + [Fact] + [AutoInitShutdown] + public void Click_Another_View_Close_An_Open_Menu () + { + var menu = new MenuBar + { + Menus = + [ + new ("File", new MenuItem [] { new ("New", "", null) }) + ] + }; + + var btnClicked = false; + var btn = new Button { Y = 4, Text = "Test" }; + btn.Accept += (s, e) => btnClicked = true; + var top = new Toplevel (); + top.Add (menu, btn); + Application.Begin (top); + + Application.OnMouseEvent (new () { Position = new (0, 4), Flags = MouseFlags.Button1Clicked }); + Assert.True (btnClicked); + top.Dispose (); + } + // TODO: Lots of tests in here really test Menu and MenuItem - Move them to MenuTests.cs [Fact] @@ -1319,6 +1387,7 @@ wo return true; } + // Declare a variable for the function Func fnActionVariable = FnAction; @@ -2560,7 +2629,7 @@ Edit top.Draw (); TestHelpers.AssertDriverContentsAre (expectedMenu.ExpectedSubMenuOpen (0), output); - Assert.True (Application.OnKeyDown(menu.Key)); + Assert.True (Application.OnKeyDown (menu.Key)); Assert.False (menu.IsMenuOpen); Assert.True (tf.HasFocus); top.Draw (); @@ -2799,6 +2868,19 @@ Edit Assert.False (menu.NewKeyDownEvent (Key.Q.WithAlt)); } + [Fact] + public void SetMenus_With_Same_HotKey_Does_Not_Throws () + { + var mb = new MenuBar (); + + var i1 = new MenuBarItem ("_heey", "fff", () => { }, () => true); + + mb.Menus = new [] { i1 }; + mb.Menus = new [] { i1 }; + + Assert.Equal (Key.H, mb.Menus [0].HotKey); + } + [Fact] [AutoInitShutdown] public void ShortCut_Activates () @@ -2837,6 +2919,31 @@ Edit top.Dispose (); } + [Fact] + public void Update_ShortcutKey_KeyBindings_Old_ShortcutKey_Is_Removed () + { + var menuBar = new MenuBar + { + Menus = + [ + new ( + "_File", + new MenuItem [] + { + new ("New", "Create New", null, null, null, Key.A.WithCtrl) + } + ) + ] + }; + + Assert.Contains (Key.A.WithCtrl, menuBar.KeyBindings.Bindings); + + menuBar.Menus [0].Children [0].ShortcutKey = Key.B.WithCtrl; + + Assert.DoesNotContain (Key.A.WithCtrl, menuBar.KeyBindings.Bindings); + Assert.Contains (Key.B.WithCtrl, menuBar.KeyBindings.Bindings); + } + [Fact] public void UseKeysUpDownAsKeysLeftRight_And_UseSubMenusSingleFrame_Cannot_Be_Both_True () { @@ -3000,11 +3107,9 @@ Edit Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 8, 1), pos); - Assert.True ( - menu.NewMouseEvent ( - new () { Position = new (1, 0), Flags = MouseFlags.Button1Pressed, View = menu } - ) - ); + menu.NewMouseEvent ( + new () { Position = new (1, 0), Flags = MouseFlags.Button1Pressed, View = menu } + ); top.Draw (); expected = @" @@ -3019,14 +3124,12 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 10, 6), pos); - Assert.False ( - menu.NewMouseEvent ( - new () - { - Position = new (1, 2), Flags = MouseFlags.ReportMousePosition, View = Application.Top.Subviews [1] - } - ) - ); + menu.NewMouseEvent ( + new () + { + Position = new (1, 2), Flags = MouseFlags.ReportMousePosition, View = Application.Top.Subviews [1] + } + ); top.Draw (); expected = @" @@ -3064,11 +3167,9 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 10, 6), pos); - Assert.True ( - menu.NewMouseEvent ( - new () { Position = new (70, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top } - ) - ); + menu.NewMouseEvent ( + new () { Position = new (70, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top } + ); top.Draw (); expected = @" @@ -3329,7 +3430,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 10, 6), pos); - Assert.True (menu.NewMouseEvent (new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [1] })); + Assert.False (menu.NewMouseEvent (new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [1] })); top.Draw (); expected = @" @@ -3345,7 +3446,7 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 15, 7), pos); - Assert.True (menu.NewMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [2] })); + menu.NewMouseEvent (new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [2] }); top.Draw (); expected = @" @@ -3514,11 +3615,9 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 8, 4), pos); - Assert.True ( - menu.NewMouseEvent ( - new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [1] } - ) - ); + menu.NewMouseEvent ( + new () { Position = new (1, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [1] } + ); top.Draw (); expected = @" @@ -3532,11 +3631,9 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 13, 5), pos); - Assert.True ( - menu.NewMouseEvent ( - new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [2] } - ) - ); + menu.NewMouseEvent ( + new () { Position = new (1, 1), Flags = MouseFlags.Button1Clicked, View = Application.Top.Subviews [2] } + ); top.Draw (); expected = @" @@ -3549,11 +3646,9 @@ Edit pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); Assert.Equal (new (1, 0, 8, 4), pos); - Assert.False ( - menu.NewMouseEvent ( - new () { Position = new (70, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top } - ) - ); + menu.NewMouseEvent ( + new () { Position = new (70, 2), Flags = MouseFlags.Button1Clicked, View = Application.Top } + ); top.Draw (); expected = @" @@ -3611,23 +3706,6 @@ Edit // The expected strings when the menu is closed public string ClosedMenuText => MenuBarText + "\n"; - // Each MenuBar title has a 1 space pad on each side - // See `static int leftPadding` and `static int rightPadding` on line 1037 of Menu.cs - public string MenuBarText - { - get - { - var txt = string.Empty; - - foreach (MenuBarItem m in Menus) - { - txt += " " + m.Title + " "; - } - - return txt; - } - } - public string ExpectedBottomRow (int i) { return $"{CM.Glyphs.LLCorner}{new (CM.Glyphs.HLine.ToString () [0], Menus [i].Children [0].TitleLength + 3)}{CM.Glyphs.LRCorner} \n"; @@ -3662,6 +3740,23 @@ Edit return $"{CM.Glyphs.ULCorner}{new (CM.Glyphs.HLine.ToString () [0], Menus [i].Children [0].TitleLength + 3)}{CM.Glyphs.URCorner} \n"; } + // Each MenuBar title has a 1 space pad on each side + // See `static int leftPadding` and `static int rightPadding` on line 1037 of Menu.cs + public string MenuBarText + { + get + { + var txt = string.Empty; + + foreach (MenuBarItem m in Menus) + { + txt += " " + m.Title + " "; + } + + return txt; + } + } + // Padding for the X of the sub menu Frame // Menu.cs - Line 1239 in `internal void OpenMenu` is where the Menu is created private string ExpectedPadding (int i) @@ -3703,111 +3798,4 @@ Edit Add (menu); } } - - [Fact] - [AutoInitShutdown] - public void Click_Another_View_Close_An_Open_Menu () - { - var menu = new MenuBar - { - Menus = - [ - new ("File", new MenuItem [] { new ("New", "", null) }) - ] - }; - - var btnClicked = false; - var btn = new Button { Y = 4, Text = "Test" }; - btn.Accept += (s, e) => btnClicked = true; - var top = new Toplevel (); - top.Add (menu, btn); - Application.Begin (top); - - Application.OnMouseEvent (new () { Position = new (0, 4), Flags = MouseFlags.Button1Clicked }); - Assert.True (btnClicked); - top.Dispose (); - } - - [Fact] - public void Update_ShortcutKey_KeyBindings_Old_ShortcutKey_Is_Removed () - { - var menuBar = new MenuBar () - { - Menus = - [ - new MenuBarItem ( - "_File", - new MenuItem [] - { - new MenuItem ("New", "Create New", null, null, null, Key.A.WithCtrl) - } - ) - ] - }; - - Assert.Contains (Key.A.WithCtrl, menuBar.KeyBindings.Bindings); - - menuBar.Menus [0].Children [0].ShortcutKey = Key.B.WithCtrl; - - Assert.DoesNotContain (Key.A.WithCtrl, menuBar.KeyBindings.Bindings); - Assert.Contains (Key.B.WithCtrl, menuBar.KeyBindings.Bindings); - } - - [Fact] - public void SetMenus_With_Same_HotKey_Does_Not_Throws () - { - var mb = new MenuBar (); - - var i1 = new MenuBarItem ("_heey", "fff", () => { }, () => true); - - mb.Menus = new MenuBarItem [] { i1 }; - mb.Menus = new MenuBarItem [] { i1 }; - - Assert.Equal (Key.H, mb.Menus [0].HotKey); - } - - [Fact] - [AutoInitShutdown] - public void AddMenuBarItem_RemoveMenuItem_Dynamically () - { - var menuBar = new MenuBar (); - var menuBarItem = new MenuBarItem { Title = "_New" }; - var action = ""; - var menuItem = new MenuItem { Title = "_Item", Action = () => action = "I", Parent = menuBarItem }; - Assert.Equal ("n", menuBarItem.HotKey); - Assert.Equal ("i", menuItem.HotKey); - Assert.Empty (menuBar.Menus); - menuBarItem.AddMenuBarItem (menuItem); - menuBar.Menus = [menuBarItem]; - Assert.Single (menuBar.Menus); - Assert.Single (menuBar.Menus [0].Children); - Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings); - Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings); - - var top = new Toplevel (); - top.Add (menuBar); - Application.Begin (top); - - top.NewKeyDownEvent (Key.N.WithAlt); - Application.MainLoop.RunIteration (); - Assert.True (menuBar.IsMenuOpen); - Assert.Equal ("", action); - - top.NewKeyDownEvent (Key.I); - Application.MainLoop.RunIteration (); - Assert.False (menuBar.IsMenuOpen); - Assert.Equal ("I", action); - - menuItem.RemoveMenuItem (); - Assert.Single (menuBar.Menus); - Assert.Null (menuBar.Menus [0].Children); - Assert.Contains (Key.N.WithAlt, menuBar.KeyBindings.Bindings); - Assert.DoesNotContain (Key.I, menuBar.KeyBindings.Bindings); - - menuBarItem.RemoveMenuItem (); - Assert.Empty (menuBar.Menus); - Assert.DoesNotContain (Key.N.WithAlt, menuBar.KeyBindings.Bindings); - - top.Dispose (); - } } diff --git a/UnitTests/Views/TextFieldTests.cs b/UnitTests/Views/TextFieldTests.cs index 3dff06e3a..6d9c09210 100644 --- a/UnitTests/Views/TextFieldTests.cs +++ b/UnitTests/Views/TextFieldTests.cs @@ -1983,4 +1983,68 @@ Les Miśerables", }; } } + + [Fact] + public void Autocomplete_Popup_Added_To_SuperView_On_Init () + { + View superView = new () + { + CanFocus = true, + }; + + TextField t = new (); + + superView.Add (t); + Assert.Single (superView.Subviews); + + superView.BeginInit (); + superView.EndInit (); + + Assert.Equal (2, superView.Subviews.Count); + } + + + [Fact] + public void Autocomplete__Added_To_SuperView_On_Add () + { + View superView = new () + { + CanFocus = true, + Id = "superView", + }; + + superView.BeginInit (); + superView.EndInit (); + Assert.Empty (superView.Subviews); + + TextField t = new () + { + Id = "t" + }; + + superView.Add (t); + + Assert.Equal (2, superView.Subviews.Count); + } + + + [Fact] + public void Autocomplete_Visible_False_By_Default () + { + View superView = new () + { + CanFocus = true, + }; + + TextField t = new (); + + superView.Add (t); + superView.BeginInit (); + superView.EndInit (); + + Assert.Equal (2, superView.Subviews.Count); + + Assert.True (t.Visible); + Assert.False (t.Autocomplete.Visible); + } } diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index f96f7bec0..364fb228d 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -8557,4 +8557,67 @@ line. } } + [Fact] + public void Autocomplete_Popup_Added_To_SuperView_On_Init () + { + View superView = new () + { + CanFocus = true, + }; + + TextView t = new (); + + superView.Add (t); + Assert.Single (superView.Subviews); + + superView.BeginInit (); + superView.EndInit (); + + Assert.Equal (2, superView.Subviews.Count); + } + + + [Fact] + public void Autocomplete__Added_To_SuperView_On_Add () + { + View superView = new () + { + CanFocus = true, + Id = "superView", + }; + + superView.BeginInit (); + superView.EndInit (); + Assert.Empty (superView.Subviews); + + TextView t = new () + { + Id = "t" + }; + + superView.Add (t); + + Assert.Equal (2, superView.Subviews.Count); + } + + + [Fact] + public void Autocomplete_Visible_False_By_Default () + { + View superView = new () + { + CanFocus = true, + }; + + TextView t = new (); + + superView.Add (t); + superView.BeginInit (); + superView.EndInit (); + + Assert.Equal (2, superView.Subviews.Count); + + Assert.True (t.Visible); + Assert.False (t.Autocomplete.Visible); + } } diff --git a/UnitTests/Views/TileViewTests.cs b/UnitTests/Views/TileViewTests.cs index 686d80710..205409efb 100644 --- a/UnitTests/Views/TileViewTests.cs +++ b/UnitTests/Views/TileViewTests.cs @@ -973,13 +973,13 @@ public class TileViewTests Assert.Equal (6, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width); Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y); Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height); - Assert.IsType (subSplit.Tiles.ElementAt (0).ContentView.Subviews.Single ()); + //Assert.IsType (subSplit.Tiles.ElementAt (0).ContentView.Subviews.Single ()); Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X); Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width); Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y); Assert.Equal (4, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height); - Assert.IsType (subSplit.Tiles.ElementAt (1).ContentView.Subviews.Single ()); + //Assert.IsType (subSplit.Tiles.ElementAt (1).ContentView.Subviews.Single ()); } [Fact] @@ -1524,13 +1524,13 @@ public class TileViewTests Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width); Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y); Assert.Equal (4, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height); - Assert.IsType (subSplit.Tiles.ElementAt (0).ContentView.Subviews.Single ()); + //Assert.IsType (subSplit.Tiles.ElementAt (0).ContentView.Subviews.Single ()); Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X); Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width); Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y); Assert.Equal (3, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height); - Assert.IsType (subSplit.Tiles.ElementAt (1).ContentView.Subviews.Single ()); + //Assert.IsType (subSplit.Tiles.ElementAt (1).ContentView.Subviews.Single ()); } [Fact]