Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Fixed issues with autocomplete selecting category items (win)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrekV committed May 28, 2018
1 parent 2ae2397 commit bd4edf4
Showing 1 changed file with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public void FillList(ListBox listBox, Action<AutoCompleteItem> selectWithClick,
}
visibleItems = items;
LB.ItemsSource = visibleItems;

}
}

Expand Down Expand Up @@ -212,7 +211,7 @@ public void Complete(string input)
visibleItems = filteredItems;
}
LB.ItemsSource = visibleItems;
this.selectIndex(1);
this.selectFirstItem(0);
}

private bool Filter(object item)
Expand Down Expand Up @@ -257,6 +256,19 @@ private void validateSelection()
* */
}

private void selectFirstItem(int index)
{
if (this.visibleItems.Count == 0 || index >= this.visibleItems.Count)
return;

if (this.visibleItems[index].Type < 0)
{
this.selectFirstItem(++index);
return;
}
this.selectIndex(index);
}

private void selectIndex(int index)
{
if (index < 0 || this.visibleItems.Count == 0 || index >= this.visibleItems.Count)
Expand All @@ -277,13 +289,15 @@ public void SelectNext()

var i = this.selectedIndex + 1;
if (i == this.visibleItems.Count)
{
i = 0;
}

if (this.visibleItems[i].Type < 0)
{
i++;
if (i == this.visibleItems.Count)
i = 0;
this.selectedIndex = i;
this.SelectNext();
return;
}
this.selectIndex(i);
}
Expand All @@ -295,15 +309,16 @@ public void SelectPrevious()

var i = this.selectedIndex - 1;
if (i < 0)
i = this.visibleItems.Count - 1;

{
i = this.visibleItems.Count - 1;
}

if (this.visibleItems[i].Type < 0)
{
i--;
if (i < 0)
i = this.visibleItems.Count - 1;
this.selectedIndex = i;
this.SelectPrevious();
return;
}

this.selectIndex(i);
}

Expand Down

0 comments on commit bd4edf4

Please sign in to comment.