Skip to content
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

[WIP] Fix Completion Tooltip Placement #386

Merged
merged 1 commit into from
Dec 9, 2023
Merged
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
54 changes: 26 additions & 28 deletions src/AvaloniaEdit/CodeCompletion/CompletionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public CompletionWindow(TextArea textArea) : base(textArea)
{
IsLightDismissEnabled = true,
PlacementTarget = this,
Placement = PlacementMode.RightEdgeAlignedTop,
Child = _toolTipContent,
};

Expand Down Expand Up @@ -92,40 +91,39 @@ private void CompletionList_SelectionChanged(object sender, SelectionChangedEven

var item = CompletionList.SelectedItem;
var description = item?.Description;
if (description != null)


if (description != null && Host is Control placementTarget && CompletionList.CurrentList != null)
{
if (description is string descriptionText)
_toolTipContent.Content = description;

double yOffset = 0;
var selectedIndex = CompletionList.ListBox.SelectedIndex;

var itemContainer = CompletionList.ListBox.ContainerFromIndex(selectedIndex);

if (itemContainer != null)
{
_toolTipContent.Content = new TextBlock
{
Text = descriptionText,
TextWrapping = TextWrapping.Wrap
};
_toolTip.Placement = PlacementMode.RightEdgeAlignedTop;
var position = itemContainer.TranslatePoint(new Point(0, 0), placementTarget);
if (position.HasValue) yOffset = position.Value.Y;
}
else
{
_toolTipContent.Content = description;
}

_toolTip.IsOpen = false; //Popup needs to be closed to change position

// Calculate offset for tooltip
var popupRoot = Host as PopupRoot;
if (CompletionList.CurrentList != null)
else
{
double yOffset = 0;
var itemContainer = CompletionList.ListBox.ContainerFromItem(item);
if (popupRoot != null && itemContainer != null)
//When scrolling down the container is not always ready
//If that happens we align the tooltip at the bottom or top
if (CompletionList.ListBox.FirstVisibleItem < selectedIndex)
{
var position = itemContainer.TranslatePoint(new Point(0, 0), popupRoot);
if (position.HasValue)
yOffset = position.Value.Y;
_toolTip.Placement = PlacementMode.RightEdgeAlignedBottom;
}
else
{
_toolTip.Placement = PlacementMode.RightEdgeAlignedTop;
}

_toolTip.Offset = new Point(2, yOffset);
}

_toolTip.PlacementTarget = popupRoot;

_toolTip.Offset = new Point(2, yOffset);
_toolTip.PlacementTarget = placementTarget;
_toolTip.IsOpen = true;
}
else
Expand Down