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

Fix for the issue with Autocomplete menu. #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 23 additions & 13 deletions FastColoredTextBox/AutocompleteMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,12 @@ internal void DoAutocomplete(bool forced)
}
}

if (foundSelected)
{
AdjustScroll();
DoSelectedVisible();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have disabled scrolling to selected item.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, those calls are redundant since both those methods are called on lines 439 and 440 (AdjustScroll() is called from _Invalidate()). Behaviour is totally same if we would uncomment lines (420-423) but those calls are unnecessary.
I've tested this and it scrolls fine to the selected item.

}
// redundant call
//if (foundSelected)
//{
// AdjustScroll();
// DoSelectedVisible();
//}
}

//show popup menu
Expand All @@ -436,7 +437,7 @@ internal void DoAutocomplete(bool forced)
}

DoSelectedVisible();
Invalidate();
_Invalidate();
}
else
Menu.Close();
Expand Down Expand Up @@ -505,6 +506,11 @@ void AdjustScroll()
if (oldItemCount == visibleItems.Count)
return;

if (oldItemCount > visibleItems.Count)
{
base.Refresh();
}

int needHeight = ItemHeight * visibleItems.Count + 1;
Height = Math.Min(needHeight, MaximumSize.Height);
Menu.CalcSize();
Expand All @@ -515,8 +521,6 @@ void AdjustScroll()

protected override void OnPaint(PaintEventArgs e)
{
AdjustScroll();

var itemHeight = ItemHeight;
int startI = VerticalScroll.Value / itemHeight - 1;
int finishI = (VerticalScroll.Value + ClientSize.Height) / itemHeight + 1;
Expand Down Expand Up @@ -554,10 +558,16 @@ protected override void OnPaint(PaintEventArgs e)
}
}

protected void _Invalidate()
{
AdjustScroll();
Invalidate();
}

protected override void OnScroll(ScrollEventArgs se)
{
base.OnScroll(se);
Invalidate();
_Invalidate();
}

protected override void OnMouseClick(MouseEventArgs e)
Expand All @@ -568,15 +578,15 @@ protected override void OnMouseClick(MouseEventArgs e)
{
FocussedItemIndex = PointToItemIndex(e.Location);
DoSelectedVisible();
Invalidate();
_Invalidate();
}
}

protected override void OnMouseDoubleClick(MouseEventArgs e)
{
base.OnMouseDoubleClick(e);
FocussedItemIndex = PointToItemIndex(e.Location);
Invalidate();
_Invalidate();
OnSelecting();
}

Expand All @@ -599,7 +609,7 @@ internal virtual void OnSelecting()
if (args.Cancel)
{
FocussedItemIndex = args.SelectedIndex;
Invalidate();
_Invalidate();
return;
}

Expand Down Expand Up @@ -704,7 +714,7 @@ public void SelectNext(int shift)
FocussedItemIndex = Math.Max(0, Math.Min(FocussedItemIndex + shift, visibleItems.Count - 1));
DoSelectedVisible();
//
Invalidate();
_Invalidate();
}

private void DoSelectedVisible()
Expand Down