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

Improve recent repository list keyboard navigation #10400

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void ShowRecentRepositories(bool reloadData = true)

_hasInvalidRepos = false;

var groups = Enumerable.Repeat(_lvgRecentRepositories, 1)
var groups = new[] { _lvgRecentRepositories }
.Concat(recentRepositories.Concat(favouriteRepositories)
.Select(repo => repo.Repo.Category)
.Where(c => !string.IsNullOrWhiteSpace(c))
Expand Down Expand Up @@ -388,7 +388,7 @@ private IEnumerable<Repository> GetRepositories()
{
return listView1.Items.Cast<ListViewItem>()
.Select(lvi => (Repository)lvi.Tag)
.Where(_ => _ is not null);
.Where(r => r is not null);
}

private static SelectedRepositoryItem? GetSelectedRepositoryItem(ToolStripItem? menuItem)
Expand Down Expand Up @@ -665,6 +665,10 @@ private void TextBoxSearch_KeyDown(object sender, KeyEventArgs e)

TryOpenRepository(items[0].Tag as Repository);
}
else if (e.KeyCode == Keys.Down)
{
listView1.Focus();
}
}

private void listView1_MouseMove(object sender, MouseEventArgs e)
Expand All @@ -677,6 +681,29 @@ private void listView1_MouseLeave(object sender, EventArgs e)
HoveredItem = null;
}

private void listView1_GotFocus(object sender, EventArgs e)
{
if (listView1.Items.Count > 0 && listView1.SelectedItems.Count == 0)
{
listView1.Items[0].Selected = true;
}
}

private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up && listView1.SelectedItems.Count > 0)
{
// Compare current item to the very first item to see if it's at the top
ListViewItem selectedItem = listView1.SelectedItems[0];
if (selectedItem.Bounds.Y == listView1.Items[0].Bounds.Y)
{
textBoxSearch.Focus();
selectedItem.Selected = true;
e.Handled = true;
}
}
}

private void mnuConfigure_Click(object sender, EventArgs e)
{
using FormRecentReposSettings frm = new();
Expand Down