From d69de86ba430b7624dca2c88f3453968105ef466 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 8 Jan 2024 19:08:48 +0000 Subject: [PATCH 1/3] Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. (#3142) --- UnitTests/Input/ResponderTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/UnitTests/Input/ResponderTests.cs b/UnitTests/Input/ResponderTests.cs index 2b01c2cca..452accd1a 100644 --- a/UnitTests/Input/ResponderTests.cs +++ b/UnitTests/Input/ResponderTests.cs @@ -139,6 +139,9 @@ public class ResponderTests { [Fact] public void Responder_Not_Notifying_Dispose () { + // Only clear before because need to test after assert + Responder.Instances.Clear (); + var container1 = new View () { Id = "Container1" }; var view = new View () { Id = "View" }; @@ -175,6 +178,9 @@ public class ResponderTests { [Fact] public void Disposing_Event_Notify_All_Subscribers_On_The_Second_Container () { + // Only clear before because need to test after assert + Responder.Instances.Clear (); + var container1 = new View () { Id = "Container1" }; var view = new View () { Id = "View" }; @@ -212,6 +218,9 @@ public class ResponderTests { [Fact] public void Disposing_Event_Notify_All_Subscribers_On_The_First_Container () { + // Only clear before because need to test after assert + Responder.Instances.Clear (); + var container1 = new View () { Id = "Container1" }; var count = 0; From eb45036848c3fcbb8851b18f02d09e282057b41f Mon Sep 17 00:00:00 2001 From: Ross Ferguson Date: Mon, 8 Jan 2024 19:09:59 +0000 Subject: [PATCH 2/3] Fixes #3132 #3138 ComboBox (v2) One key delay when keying down arrow. Up arrow does not move back to searchbox (#3133) * Fixes #3132 ComboBox one key delay when keying down arrow to move into dropdown list * Fixes #3138. ComboBox. Up arrow does not move you back into the search box when at the top of dropdown list * Fixes #3138 Fix unittest --------- Co-authored-by: Tig --- Terminal.Gui/Views/ComboBox.cs | 66 +++++++++++++----------- UICatalog/Properties/launchSettings.json | 4 ++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 851719c24..2be429199 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -10,7 +10,7 @@ using System.Collections; using System.Collections.Generic; using System.Text; -namespace Terminal.Gui; +namespace Terminal.Gui; /// /// Provides a drop-down list of items the user can select from. @@ -32,6 +32,7 @@ public class ComboBox : View { { _container = container ?? throw new ArgumentNullException (nameof (container), "ComboBox container cannot be null."); HideDropdownListOnClick = hideDropdownListOnClick; + AddCommand (Command.LineUp, () => _container.MoveUpList ()); } public bool HideDropdownListOnClick { @@ -589,18 +590,23 @@ public class ComboBox : View { bool? MoveUp () { - if (_search.HasFocus) { - // stop odd behavior on KeyUp when search has focus - return true; + if (HasItems ()) { + _listview.MoveUp (); } + return true; + } + bool? MoveUpList () + { if (_listview.HasFocus && _listview.SelectedItem == 0 && _searchset?.Count > 0) // jump back to search { _search.CursorPosition = _search.Text.GetRuneCount (); _search.SetFocus (); - return true; + } else { + MoveUp (); } - return null; + + return true; } bool? MoveDown () @@ -612,6 +618,8 @@ public class ComboBox : View { _listview.SetFocus (); if (_listview.SelectedItem > -1) { SetValue (_searchset [_listview.SelectedItem]); + } else { + _listview.SelectedItem = 0; } } else { _listview.TabStop = false; @@ -731,18 +739,18 @@ public class ComboBox : View { _isShow = false; } - private int GetSelectedItemFromSource (string searchText) - { - if (_source is null) { - return -1; - } - for (int i = 0; i < _searchset.Count; i++) { - if (_searchset [i].ToString () == searchText) { - return i; - } - } + private int GetSelectedItemFromSource (string searchText) + { + if (_source is null) { return -1; } + for (int i = 0; i < _searchset.Count; i++) { + if (_searchset [i].ToString () == searchText) { + return i; + } + } + return -1; + } /// /// Reset to full original list @@ -784,20 +792,20 @@ public class ComboBox : View { } } - private void Search_Changed (object sender, TextChangedEventArgs e) - { - if (_source is null) { // Object initialization - return; - } + private void Search_Changed (object sender, TextChangedEventArgs e) + { + if (_source is null) { // Object initialization + return; + } - if (string.IsNullOrEmpty (_search.Text) && string.IsNullOrEmpty (e.OldValue)) { - ResetSearchSet (); - } else if (_search.Text != e.OldValue) { - if (_search.Text.Length < e.OldValue.Length) { - _selectedItem = -1; - } - _isShow = true; - ResetSearchSet (noCopy: true); + if (string.IsNullOrEmpty (_search.Text) && string.IsNullOrEmpty (e.OldValue)) { + ResetSearchSet (); + } else if (_search.Text != e.OldValue) { + if (_search.Text.Length < e.OldValue.Length) { + _selectedItem = -1; + } + _isShow = true; + ResetSearchSet (noCopy: true); foreach (object item in _source.ToList ()) { // Iterate to preserver object type and force deep copy diff --git a/UICatalog/Properties/launchSettings.json b/UICatalog/Properties/launchSettings.json index 48c729999..c105de4e1 100644 --- a/UICatalog/Properties/launchSettings.json +++ b/UICatalog/Properties/launchSettings.json @@ -65,6 +65,10 @@ "MenuBarScenario": { "commandName": "Project", "commandLineArgs": "MenuBar" + }, + "ListView & ComboBox": { + "commandName": "Project", + "commandLineArgs": "\"ListView & ComboBox\"" } } } \ No newline at end of file From 3150d43979735d25f7ddf6dd63b601a92f5343a9 Mon Sep 17 00:00:00 2001 From: joebart457 <59572954+joebart457@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:11:11 -0800 Subject: [PATCH 3/3] Fixes #3144. TextView Autocomplete does not insert capital letters (#3145) * Fixes #3144. TextView Autocomplete does not insert capital letters * Fixes #3144. Fix unit test for fix of TextView Autocomplete does not insert capital letters --- Terminal.Gui/Views/TextView.cs | 6 +++--- UnitTests/Text/AutocompleteTests.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index ef0132154..6ed4521d7 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -3026,14 +3026,14 @@ public class TextView : View { public void InsertText (string toAdd) { foreach (char ch in toAdd) { - KeyCode key; + Key key; try { - key = (KeyCode)ch; + key = new Key(ch); } catch (Exception) { throw new ArgumentException ($"Cannot insert character '{ch}' because it does not map to a Key"); } - InsertText (new Key (key)); + InsertText (key); if (NeedsDisplay) { Adjust (); diff --git a/UnitTests/Text/AutocompleteTests.cs b/UnitTests/Text/AutocompleteTests.cs index 5f853abba..ad7bc6e09 100644 --- a/UnitTests/Text/AutocompleteTests.cs +++ b/UnitTests/Text/AutocompleteTests.cs @@ -153,7 +153,7 @@ namespace Terminal.Gui.TextTests { Assert.Equal (3, g.AllSuggestions.Count); Assert.True (tv.NewKeyDownEvent (new (tv.Autocomplete.SelectionKey))); tv.PositionCursor (); - Assert.Equal ($"fortunately Fortunately super feature.", tv.Text); + Assert.Equal ($"Fortunately Fortunately super feature.", tv.Text); Assert.Equal (new Point (11, 0), tv.CursorPosition); Assert.Empty (tv.Autocomplete.Suggestions); Assert.Equal (3, g.AllSuggestions.Count);