Skip to content

Commit

Permalink
Improve keyboard usability in searchbox
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Apr 2, 2023
1 parent 1ad9a32 commit 696bd58
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/ScriptRunner/ScriptRunner.GUI/Views/SearchBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,46 @@ public SearchBox(IReadOnlyList<ScriptConfig> viewModelActions, IReadOnlyList<Rec
{
if (FilteredItems.ItemCount > 0)
{
FilteredItems.SelectedIndex = 0;

this.FilteredItems.Focus();
if (FilteredItems.ItemContainerGenerator.ContainerFromIndex(0) is { } item)
{
FilteredItems.Selection.Select(0);
item.Focus();
}
}
}else if (args.Key == Key.Enter)
{
ChoseSelected();
}


};

this.FilteredItems.KeyUp += (sender, args) =>
this.FilteredItems.KeyDown += (sender, args) =>
{
if (args.Key == Key.Up)
{
if (FilteredItems.SelectedIndex == 0)
{
this.SearchBoxInput.Focus();


}
}
else if (args.Key == Key.Enter)

else if (args.Key == Key.Down)
{
if (FilteredItems.SelectedIndex == FilteredItems.ItemCount - 1)
{
this.SearchBoxInput.Focus();
}
}



};
this.FilteredItems.KeyUp += (sender, args) =>
{
if (args.Key == Key.Enter)
{
ChoseSelected();
}
Expand All @@ -87,13 +101,13 @@ public SearchBox(IReadOnlyList<ScriptConfig> viewModelActions, IReadOnlyList<Rec



this.FilteredItems.KeyDown += (sender, args) =>
{
if (args.Key is not Key.Escape or Key.Down or Key.Up or Key.Enter)
{
SearchBoxInput.Focus();
}
};
//this.FilteredItems.KeyDown += (sender, args) =>
//{
// if (args.Key is not Key.Escape or Key.Down or Key.Up or Key.Enter)
// {
// SearchBoxInput.Focus();
// }
//};

}

Expand Down

0 comments on commit 696bd58

Please sign in to comment.