Browse Source

Completion popup wrapping for arrow key navigation

pull/240/head
Ionite 1 year ago
parent
commit
205218b01a
No known key found for this signature in database
  1. 4
      StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionList.cs
  2. 22
      StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionListBox.cs

4
StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionList.cs

@ -202,11 +202,11 @@ public class CompletionList : TemplatedControl
{
case Key.Down:
e.Handled = true;
_listBox.SelectIndex(_listBox.SelectedIndex + 1);
_listBox.SelectNextIndexWithLoop();
break;
case Key.Up:
e.Handled = true;
_listBox.SelectIndex(_listBox.SelectedIndex - 1);
_listBox.SelectPreviousIndexWithLoop();
break;
case Key.PageDown:
e.Handled = true;

22
StabilityMatrix.Avalonia/Controls/CodeCompletion/CompletionListBox.cs

@ -91,6 +91,28 @@ public class CompletionListBox : ListBox
SelectedIndex = -1;
}
/// <summary>
/// Selects the next item. If the last item is already selected, selects the first item.
/// </summary>
public void SelectNextIndexWithLoop()
{
if (ItemCount <= 0)
return;
SelectIndex((SelectedIndex + 1) % ItemCount);
}
/// <summary>
/// Selects the previous item. If the first item is already selected, selects the last item.
/// </summary>
public void SelectPreviousIndexWithLoop()
{
if (ItemCount <= 0)
return;
SelectIndex((SelectedIndex - 1 + ItemCount) % ItemCount);
}
/// <summary>
/// Selects the item with the specified index and scrolls it into view.
/// </summary>

Loading…
Cancel
Save