Skip to content

Commit 2d72425

Browse files
authored
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
1 parent e1086a4 commit 2d72425

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Terminal.Gui/Views/Autocomplete/PopupAutocomplete.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public abstract partial class PopupAutocomplete : AutocompleteBase
1111
private bool _closed;
1212
private Scheme _scheme;
1313
private View _hostControl;
14-
private View _top; // The _hostControl's SuperView
15-
private View _popup;
14+
private View _top; // The _hostControl's SuperView
15+
internal View _popup;
1616
private int _toRenderLength;
1717

1818
/// <summary>Creates a new instance of the <see cref="PopupAutocomplete"/> class.</summary>
@@ -70,6 +70,7 @@ public override View HostControl
7070
{
7171
_top.Initialized += _top_Initialized;
7272
}
73+
7374
_top.Removed += _top_Removed;
7475
}
7576
}
@@ -268,7 +269,11 @@ public override void RenderOverlay (Point renderAt)
268269
else if (!Visible || HostControl?.HasFocus == false || Suggestions.Count == 0)
269270
{
270271
LastPopupPos = null;
271-
Visible = false;
272+
273+
if (Visible)
274+
{
275+
Close ();
276+
}
272277

273278
if (Suggestions.Count == 0)
274279
{
@@ -372,16 +377,16 @@ public override void RenderOverlay (Point renderAt)
372377
if (PopupInsideContainer)
373378
{
374379
_popup.Frame = new (
375-
new (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y),
376-
new (width, height)
377-
);
380+
new (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y),
381+
new (width, height)
382+
);
378383
}
379384
else
380385
{
381386
_popup.Frame = new (
382-
renderAt with { X = HostControl.Frame.X + renderAt.X },
383-
new (width, height)
384-
);
387+
renderAt with { X = HostControl.Frame.X + renderAt.X },
388+
new (width, height)
389+
);
385390
}
386391

387392
_popup.Move (0, 0);
@@ -419,6 +424,7 @@ protected void Close ()
419424
ClearSuggestions ();
420425
Visible = false;
421426
_closed = true;
427+
422428
//RemovePopupFromTop ();
423429
_popup.Visible = false;
424430
HostControl?.SetNeedsDraw ();
@@ -561,7 +567,6 @@ private void RemovePopupFromTop ()
561567
_top?.Remove (_popup);
562568
_popup.Dispose ();
563569
_popup = null;
564-
565570
}
566571
}
567572

@@ -571,6 +576,7 @@ private void _top_Initialized (object sender, EventArgs e)
571576
{
572577
_top = sender as View;
573578
}
579+
574580
AddPopupToTop ();
575581
}
576582

Tests/UnitTests/Text/AutocompleteTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ This an long line and against TextView.
153153
This an long line and against TextView.",
154154
output
155155
);
156+
Assert.Empty (tv.Autocomplete.Suggestions);
157+
Assert.False (((PopupAutocomplete)tv.Autocomplete)._popup.Visible);
158+
156159
top.Dispose ();
157160
}
158161

0 commit comments

Comments
 (0)