Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
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
25 changes: 15 additions & 10 deletions src/GitHub.VisualStudio/UI/GitHubPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ protected override void Initialize()
// Using JoinableTaskFactory from parent AsyncPackage. That way if VS shuts down before this
// work is done, we won't risk crashing due to arbitrary work going on in background threads.
var asyncPackage = (AsyncPackage)Package;
viewModelTask = asyncPackage.JoinableTaskFactory.RunAsync(() => InitializeAsync(asyncPackage));
JoinableTaskFactory = asyncPackage.JoinableTaskFactory;

viewModelTask = JoinableTaskFactory.RunAsync(() => InitializeAsync(asyncPackage));
}

public Task<IGitHubPaneViewModel> GetViewModelAsync() => viewModelTask.JoinAsync();
Expand Down Expand Up @@ -123,7 +125,7 @@ public override IVsSearchTask CreateSearch(uint dwCookie, IVsSearchQuery pSearch

if (pane != null)
{
return new SearchTask(pane, dwCookie, pSearchQuery, pSearchCallback);
return new SearchTask(JoinableTaskFactory, pane, dwCookie, pSearchQuery, pSearchCallback);
}

return null;
Expand Down Expand Up @@ -175,37 +177,38 @@ void UpdateSearchHost(bool enabled, string query)
{
SearchHost.IsEnabled = enabled;

var searchString = SearchHost.SearchQuery?.SearchString;
if (searchString?.Trim() != query?.Trim())
if (SearchHost.SearchQuery?.SearchString != query)
{
// SearchAsync will crash the process if we send it a duplicate string.
// There is a SearchTrimsWhitespace setting that makes searched with leading or trailing
// white-space appear as duplicates. We compare the query with trimmed white-space to avoid this.
// https://github.com/github/VisualStudio/issues/1948
SearchHost.SearchAsync(query != null ? new SearchQuery(query) : null);
}
}
}

class SearchTask : VsSearchTask
{
readonly JoinableTaskFactory joinableTaskFactory;
readonly IGitHubPaneViewModel viewModel;

public SearchTask(
JoinableTaskFactory joinableTaskFactory,
IGitHubPaneViewModel viewModel,
uint dwCookie,
IVsSearchQuery pSearchQuery,
IVsSearchCallback pSearchCallback)
: base(dwCookie, pSearchQuery, pSearchCallback)
{
this.joinableTaskFactory = joinableTaskFactory;
this.viewModel = viewModel;
}

protected override void OnStartSearch()
{
ThreadHelper.ThrowIfNotOnUIThread();
joinableTaskFactory.RunAsync(async () =>
{
await joinableTaskFactory.SwitchToMainThreadAsync();
viewModel.SearchQuery = SearchQuery.SearchString;
});

viewModel.SearchQuery = SearchQuery.SearchString;
base.OnStartSearch();
}

Expand All @@ -224,5 +227,7 @@ public SearchQuery(string query)

public uint GetTokens(uint dwMaxTokens, IVsSearchToken[] rgpSearchTokens) => 0;
}

public JoinableTaskFactory JoinableTaskFactory { get; private set; }
}
}