From 2d72425ee3d65763f06bddb3348bcbe8015bfe54 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 9 Jun 2025 21:30:57 +0100 Subject: [PATCH] Fixes #4127. PopupAutocomplete visible not updating when there are no suggestions (#4128) * Fixes #4127. PopupAutocomplete visible not updating when there are no suggestions * Code cleanup for re-run git actions --- .../Views/Autocomplete/PopupAutocomplete.cs | 26 ++++++++++++------- Tests/UnitTests/Text/AutocompleteTests.cs | 3 +++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Terminal.Gui/Views/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Views/Autocomplete/PopupAutocomplete.cs index 5b2475fb0..1c977715e 100644 --- a/Terminal.Gui/Views/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Views/Autocomplete/PopupAutocomplete.cs @@ -11,8 +11,8 @@ public abstract partial class PopupAutocomplete : AutocompleteBase private bool _closed; private Scheme _scheme; private View _hostControl; - private View _top; // The _hostControl's SuperView - private View _popup; + private View _top; // The _hostControl's SuperView + internal View _popup; private int _toRenderLength; /// Creates a new instance of the class. @@ -70,6 +70,7 @@ public abstract partial class PopupAutocomplete : AutocompleteBase { _top.Initialized += _top_Initialized; } + _top.Removed += _top_Removed; } } @@ -268,7 +269,11 @@ public abstract partial class PopupAutocomplete : AutocompleteBase else if (!Visible || HostControl?.HasFocus == false || Suggestions.Count == 0) { LastPopupPos = null; - Visible = false; + + if (Visible) + { + Close (); + } if (Suggestions.Count == 0) { @@ -372,16 +377,16 @@ public abstract partial class PopupAutocomplete : AutocompleteBase if (PopupInsideContainer) { _popup.Frame = new ( - new (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y), - new (width, height) - ); + new (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y), + new (width, height) + ); } else { _popup.Frame = new ( - renderAt with { X = HostControl.Frame.X + renderAt.X }, - new (width, height) - ); + renderAt with { X = HostControl.Frame.X + renderAt.X }, + new (width, height) + ); } _popup.Move (0, 0); @@ -419,6 +424,7 @@ public abstract partial class PopupAutocomplete : AutocompleteBase ClearSuggestions (); Visible = false; _closed = true; + //RemovePopupFromTop (); _popup.Visible = false; HostControl?.SetNeedsDraw (); @@ -561,7 +567,6 @@ public abstract partial class PopupAutocomplete : AutocompleteBase _top?.Remove (_popup); _popup.Dispose (); _popup = null; - } } @@ -571,6 +576,7 @@ public abstract partial class PopupAutocomplete : AutocompleteBase { _top = sender as View; } + AddPopupToTop (); } diff --git a/Tests/UnitTests/Text/AutocompleteTests.cs b/Tests/UnitTests/Text/AutocompleteTests.cs index 451eb0ace..86da3bc9d 100644 --- a/Tests/UnitTests/Text/AutocompleteTests.cs +++ b/Tests/UnitTests/Text/AutocompleteTests.cs @@ -153,6 +153,9 @@ This an long line and against TextView. This an long line and against TextView.", output ); + Assert.Empty (tv.Autocomplete.Suggestions); + Assert.False (((PopupAutocomplete)tv.Autocomplete)._popup.Visible); + top.Dispose (); }