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

Fixes #8146 "Keyboard navigation : Enter Key should open a recent repository" #8537

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ protected virtual void OnModuleChanged(GitModuleEventArgs args)
handler?.Invoke(this, args);
}

protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Enter)
{
// .NET 5.0 introduced collapsible `ListViewGoup`s, which we do not yet have API access to but still get rendered in the UI.
// Whenever the list of repos is collapsed but we still have a repo selected (and hidden), if we hit enter, the selected repo will
// be opened. This should be a no-op instead, however, since we cannot visually tell what repo is selected. When we upgrade
// to .NET 5.0, we can check ListViewGroup.CollapsedState to fix this issue.
return TryOpenSelectedRepository();
}

return base.ProcessDialogKey(keyData);
}

private List<string> GetCategories()
{
return GetRepositories()
Expand Down Expand Up @@ -587,23 +601,7 @@ private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
var selected = GetSelectedRepository();
if (selected == null)
{
return;
}

if (_controller.IsValidGitWorkingDir(selected.Path))
{
OnModuleChanged(new GitModuleEventArgs(new GitModule(selected.Path)));
return;
}

if (_controller.RemoveInvalidRepository(selected.Path))
{
ShowRecentRepositories();
return;
}
TryOpenSelectedRepository();
}
else if (e.Button == MouseButtons.Right)
{
Expand Down Expand Up @@ -862,5 +860,29 @@ private void OnDragEnter(object sender, DragEventArgs e)
}
}
}

// returns false only if no repository is selected
private bool TryOpenSelectedRepository()
{
var selected = GetSelectedRepository();
if (selected == null)
{
return false;
}

if (_controller.IsValidGitWorkingDir(selected.Path))
{
OnModuleChanged(new GitModuleEventArgs(new GitModule(selected.Path)));
return true;
}

if (_controller.RemoveInvalidRepository(selected.Path))
{
ShowRecentRepositories();
return true;
}

return true;
}
}
}