Skip to content

Fixes #4127. PopupAutocomplete visible not updating when there are no suggestions #4128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Terminal.Gui/Views/Autocomplete/PopupAutocomplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>Creates a new instance of the <see cref="PopupAutocomplete"/> class.</summary>
Expand Down Expand Up @@ -70,6 +70,7 @@ public override View HostControl
{
_top.Initialized += _top_Initialized;
}

_top.Removed += _top_Removed;
}
}
Expand Down Expand Up @@ -268,7 +269,11 @@ public override void RenderOverlay (Point renderAt)
else if (!Visible || HostControl?.HasFocus == false || Suggestions.Count == 0)
{
LastPopupPos = null;
Visible = false;

if (Visible)
{
Close ();
}

if (Suggestions.Count == 0)
{
Expand Down Expand Up @@ -372,16 +377,16 @@ public override void RenderOverlay (Point renderAt)
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);
Expand Down Expand Up @@ -419,6 +424,7 @@ protected void Close ()
ClearSuggestions ();
Visible = false;
_closed = true;

//RemovePopupFromTop ();
_popup.Visible = false;
HostControl?.SetNeedsDraw ();
Expand Down Expand Up @@ -561,7 +567,6 @@ private void RemovePopupFromTop ()
_top?.Remove (_popup);
_popup.Dispose ();
_popup = null;

}
}

Expand All @@ -571,6 +576,7 @@ private void _top_Initialized (object sender, EventArgs e)
{
_top = sender as View;
}

AddPopupToTop ();
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/UnitTests/Text/AutocompleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}

Expand Down
Loading