Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into fixes/2176-recognize-repository-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jcansdale authored Jan 14, 2019
2 parents 2e61444 + d05ee40 commit 5f392b6
Showing 1 changed file with 15 additions and 10 deletions.
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; }
}
}

0 comments on commit 5f392b6

Please sign in to comment.