未验证 提交 bbdcb30f 编写于 作者: D David Wengier 提交者: GitHub

Plumb through should activate (#45641)

上级 97501b04
......@@ -74,7 +74,7 @@ internal static class IStreamingFindUsagesPresenterExtensions
// If we're directly going to a location we need to activate the preview so
// that focus follows to the new cursor position. This behavior is expected
// because we are only going to navigate once successfully
if (item.TryNavigateTo(workspace, NavigationBehavior.PreviewWithFocus))
if (item.TryNavigateTo(workspace, showInPreviewTab: true, activateTab: true))
{
return true;
}
......@@ -92,7 +92,7 @@ internal static class IStreamingFindUsagesPresenterExtensions
// There was only one location to navigate to. Just directly go to that location. If we're directly
// going to a location we need to activate the preview so that focus follows to the new cursor position.
return nonExternalItems[0].TryNavigateTo(workspace, NavigationBehavior.PreviewWithFocus);
return nonExternalItems[0].TryNavigateTo(workspace, showInPreviewTab: true, activateTab: true);
}
if (presenter != null)
......
......@@ -17,14 +17,14 @@ public static bool CanNavigateTo(this DocumentSpan documentSpan)
return service.CanNavigateToSpan(workspace, documentSpan.Document.Id, documentSpan.SourceSpan);
}
public static bool TryNavigateTo(this DocumentSpan documentSpan, NavigationBehavior navigationBehavior)
public static bool TryNavigateTo(this DocumentSpan documentSpan, bool showInPreviewTab, bool activateTab)
{
var solution = documentSpan.Document.Project.Solution;
var workspace = solution.Workspace;
var service = workspace.Services.GetService<IDocumentNavigationService>();
var options = solution.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, navigationBehavior != NavigationBehavior.Normal);
options = options.WithChangedOption(NavigationOptions.ActivateProvisionalTab, navigationBehavior == NavigationBehavior.PreviewWithFocus);
var options = solution.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, showInPreviewTab);
options = options.WithChangedOption(NavigationOptions.ActivateTab, activateTab);
return service.TryNavigateToSpan(workspace, documentSpan.Document.Id, documentSpan.SourceSpan, options);
}
......
......@@ -50,7 +50,7 @@ public override bool CanNavigateTo(Workspace workspace)
return SourceSpans[0].CanNavigateTo();
}
public override bool TryNavigateTo(Workspace workspace, NavigationBehavior navigationBehavior)
public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab)
{
if (Properties.ContainsKey(NonNavigable))
{
......@@ -62,7 +62,7 @@ public override bool TryNavigateTo(Workspace workspace, NavigationBehavior navig
return TryNavigateToMetadataSymbol(workspace, symbolKey);
}
return SourceSpans[0].TryNavigateTo(navigationBehavior);
return SourceSpans[0].TryNavigateTo(showInPreviewTab, activateTab);
}
private bool CanNavigateToMetadataSymbol(Workspace workspace, string symbolKey)
......
......@@ -154,7 +154,7 @@ internal abstract partial class DefinitionItem
}
public abstract bool CanNavigateTo(Workspace workspace);
public abstract bool TryNavigateTo(Workspace workspace, NavigationBehavior navigationBehavior);
public abstract bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab);
public static DefinitionItem Create(
ImmutableArray<string> tags,
......
......@@ -15,10 +15,9 @@ internal static class NavigationOptions
public static readonly Option2<bool> PreferProvisionalTab = new Option2<bool>(nameof(NavigationOptions), nameof(PreferProvisionalTab), defaultValue: false);
/// <summary>
/// This option can be passed to the <see cref="IDocumentNavigationService"/> APIs to request that if a provisional tab
/// <see cref="PreferProvisionalTab"/> is used the navigation should still activate the tab. Defaults to false to support
/// users not losing focus while navigating through lists such as find references.
/// This option can be passed to the <see cref="IDocumentNavigationService"/> APIs to request that the navigation should activate the tab.
/// The default for the platform is to activate the tab, so turning the option off tells the platform to not activate the tab.
/// </summary>
public static readonly Option2<bool> ActivateProvisionalTab = new Option2<bool>(nameof(NavigationOptions), nameof(ActivateProvisionalTab), defaultValue: false);
public static readonly Option2<bool> ActivateTab = new Option2<bool>(nameof(NavigationOptions), nameof(ActivateTab), defaultValue: true);
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
internal enum NavigationBehavior
{
/// <summary>
/// The destination will attempt to open in a normal tab and activate
/// </summary>
Normal,
/// <summary>
/// The destination will navigate using a preview window and not activate that window.
/// Useful for cases where the user might be going through a list of items and we want to
/// make the context visible but not make focus changes
/// </summary>
PreviewWithoutFocus,
/// <summary>
/// The destination will navigate using a preview window and activate
/// </summary>
PreviewWithFocus
}
}
......@@ -62,7 +62,8 @@ public void NavigateTo()
if (document != null)
{
var navigator = _workspace.Services.GetService<IDocumentNavigationService>();
var options = _workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true);
var options = _workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true)
.WithChangedOption(NavigationOptions.ActivateTab, false);
navigator.TryNavigateToSpan(_workspace, document.Id, _span, options);
}
}
......
......@@ -34,8 +34,7 @@ protected override object GetValueWorker(string keyName)
bool ISupportsNavigation.TryNavigateTo(bool isPreview)
=> DefinitionBucket.DefinitionItem.TryNavigateTo(
Presenter._workspace,
isPreview ? NavigationBehavior.PreviewWithoutFocus : NavigationBehavior.Normal);
Presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview); // Only activate the tab if not opening in preview
protected override IList<Inline> CreateLineTextInlines()
=> DefinitionBucket.DefinitionItem.DisplayParts
......
......@@ -54,8 +54,7 @@ private class RoslynDefinitionBucket : DefinitionBucket, ISupportsNavigation
public bool TryNavigateTo(bool isPreview)
=> DefinitionItem.TryNavigateTo(
_presenter._workspace,
isPreview ? NavigationBehavior.PreviewWithoutFocus : NavigationBehavior.Normal);
_presenter._workspace, showInPreviewTab: isPreview, activateTab: !isPreview); // Only activate the tab if not opening in preview
public override bool TryGetValue(string key, out object content)
{
......
......@@ -109,7 +109,7 @@ private class ExternalDefinitionItem : DefinitionItem
public override bool CanNavigateTo(Workspace workspace) => true;
public override bool TryNavigateTo(Workspace workspace, NavigationBehavior _)
public override bool TryNavigateTo(Workspace workspace, bool showInPreviewTab, bool activateTab)
=> TryOpenFile() && TryNavigateToPosition();
private bool TryOpenFile()
......
......@@ -19,7 +19,7 @@ protected virtual EventProcessor CreateEventProcessor()
protected class EventProcessor : TableControlEventProcessorBase
{
protected static AbstractTableEntriesSnapshot<TItem> GetEntriesSnapshot(ITableEntryHandle entryHandle)
=> GetEntriesSnapshot(entryHandle, out var index);
=> GetEntriesSnapshot(entryHandle, out _);
protected static AbstractTableEntriesSnapshot<TItem> GetEntriesSnapshot(ITableEntryHandle entryHandle, out int index)
{
......@@ -44,7 +44,7 @@ public override void PreprocessNavigate(ITableEntryHandle entryHandle, TableEntr
// we might fail to navigate if we don't see the document in our solution anymore.
// that can happen if error is staled build error or user used #line pragma in C#
// to point to some random file in error or more.
e.Handled = roslynSnapshot.TryNavigateTo(index, e.IsPreview);
e.Handled = roslynSnapshot.TryNavigateTo(index, e.IsPreview, e.ShouldActivate);
}
}
}
......
......@@ -35,7 +35,7 @@ protected AbstractTableEntriesSnapshot(int version, ImmutableArray<TItem> items,
_trackingPoints = trackingPoints;
}
public abstract bool TryNavigateTo(int index, bool previewTab);
public abstract bool TryNavigateTo(int index, bool previewTab, bool activate);
public abstract bool TryGetValue(int index, string columnName, out object content);
public int VersionNumber
......@@ -148,7 +148,7 @@ private static LinePosition GetLinePosition(ITextSnapshot snapshot, ITrackingPoi
return new LinePosition(line.LineNumber, point.Position - line.Start);
}
protected static bool TryNavigateTo(Workspace workspace, DocumentId documentId, LinePosition position, bool previewTab)
protected static bool TryNavigateTo(Workspace workspace, DocumentId documentId, LinePosition position, bool previewTab, bool activate)
{
var navigationService = workspace.Services.GetService<IDocumentNavigationService>();
if (navigationService == null)
......@@ -156,7 +156,8 @@ protected static bool TryNavigateTo(Workspace workspace, DocumentId documentId,
return false;
}
var options = workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, previewTab);
var options = workspace.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, previewTab)
.WithChangedOption(NavigationOptions.ActivateTab, activate);
if (navigationService.TryNavigateToLineAndOffset(workspace, documentId, position.Line, position.Character, options))
{
return true;
......@@ -165,7 +166,7 @@ protected static bool TryNavigateTo(Workspace workspace, DocumentId documentId,
return false;
}
protected bool TryNavigateToItem(int index, bool previewTab)
protected bool TryNavigateToItem(int index, bool previewTab, bool activate)
{
var item = GetItem(index);
var documentId = item?.DocumentId;
......@@ -195,7 +196,7 @@ protected bool TryNavigateToItem(int index, bool previewTab)
position = item.GetOriginalPosition();
}
return TryNavigateTo(workspace, documentId, position, previewTab);
return TryNavigateTo(workspace, documentId, position, previewTab, activate);
}
protected static string GetFileName(string original, string mapped)
......
......@@ -196,7 +196,7 @@ public EmptySnapshot(int version)
{
}
public override bool TryNavigateTo(int index, bool previewTab) => false;
public override bool TryNavigateTo(int index, bool previewTab, bool activate) => false;
public override bool TryGetValue(int index, string columnName, out object content)
{
......
......@@ -417,8 +417,8 @@ private ErrorRank GetErrorRank(DiagnosticData item)
}
}
public override bool TryNavigateTo(int index, bool previewTab)
=> TryNavigateToItem(index, previewTab);
public override bool TryNavigateTo(int index, bool previewTab, bool activate)
=> TryNavigateToItem(index, previewTab, activate);
#region IWpfTableEntriesSnapshot
......
......@@ -280,8 +280,8 @@ private LinePosition GetLineColumn(TodoTableItem item)
item.Data.MappedColumn);
}
public override bool TryNavigateTo(int index, bool previewTab)
=> TryNavigateToItem(index, previewTab);
public override bool TryNavigateTo(int index, bool previewTab, bool activate)
=> TryNavigateToItem(index, previewTab, activate);
}
}
}
......
......@@ -204,7 +204,7 @@ public override bool TryGetValue(int index, string columnName, out object conten
}
}
public override bool TryNavigateTo(int index, bool previewTab)
public override bool TryNavigateTo(int index, bool previewTab, bool activate)
{
var item = GetItem(index);
if (item?.DocumentId == null)
......@@ -216,7 +216,7 @@ public override bool TryNavigateTo(int index, bool previewTab)
var solution = item.Workspace.CurrentSolution;
return solution.ContainsDocument(documentId) &&
TryNavigateTo(item.Workspace, documentId, item.GetOriginalPosition(), previewTab);
TryNavigateTo(item.Workspace, documentId, item.GetOriginalPosition(), previewTab, activate);
}
private DocumentId GetProperDocumentId(DiagnosticTableItem item)
......
......@@ -341,18 +341,11 @@ private bool CanMapFromSecondaryBufferToPrimaryBuffer(Workspace workspace, Docum
private IDisposable OpenNewDocumentStateScope(OptionSet options)
{
if (!options.GetOption(NavigationOptions.PreferProvisionalTab))
{
return null;
}
var state = __VSNEWDOCUMENTSTATE.NDS_Provisional;
var state = options.GetOption(NavigationOptions.PreferProvisionalTab)
? __VSNEWDOCUMENTSTATE.NDS_Provisional
: __VSNEWDOCUMENTSTATE.NDS_Permanent;
// If we're just opening the provisional tab, then do not "activate" the document
// (i.e. don't give it focus) unless specifically requested.
// This way if a user is just arrowing through a set
// of FindAllReferences results, they don't have their cursor placed into the document.
if (!options.GetOption(NavigationOptions.ActivateProvisionalTab))
if (!options.GetOption(NavigationOptions.ActivateTab))
{
state |= __VSNEWDOCUMENTSTATE.NDS_NoActivate;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册