Skip to content

Commit

Permalink
Merge pull request #54178 from dotnet/merges/release/dev16.11-to-rele…
Browse files Browse the repository at this point in the history
…ase/dev16.11-vs-deps

Merge release/dev16.11 to release/dev16.11-vs-deps
  • Loading branch information
msftbot[bot] committed Jun 17, 2021
2 parents 7205cd9 + c3c343c commit f8d332c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ public InheritanceGlyphFactory(
var membersOnLine = inheritanceMarginTag.MembersOnLine;
Contract.ThrowIfTrue(membersOnLine.IsEmpty);

// ZoomLevel of textView is percentage based. (e.g. 20 -> 400 means 20% -> 400%)
// and the scaleFactor of CrispImage is 1 based. (e.g 1 means 100%)
var scaleFactor = _textView.ZoomLevel / 100;
return new MarginGlyph.InheritanceMargin(
_threadingContext,
_streamingFindUsagesPresenter,
_classificationTypeMap,
_classificationFormatMap,
_waitIndicator,
inheritanceMarginTag,
scaleFactor);
_textView);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.InheritanceMargin.MarginGlyph
{
Expand All @@ -25,6 +26,7 @@ internal partial class InheritanceMargin
private readonly IStreamingFindUsagesPresenter _streamingFindUsagesPresenter;
private readonly IWaitIndicator _waitIndicator;
private readonly Workspace _workspace;
private readonly IWpfTextView _textView;

public InheritanceMargin(
IThreadingContext threadingContext,
Expand All @@ -33,14 +35,18 @@ public InheritanceMargin(
IClassificationFormatMap classificationFormatMap,
IWaitIndicator waitIndicator,
InheritanceMarginTag tag,
double scaleFactor)
IWpfTextView textView)
{
_threadingContext = threadingContext;
_streamingFindUsagesPresenter = streamingFindUsagesPresenter;
_workspace = tag.Workspace;
_waitIndicator = waitIndicator;
_textView = textView;
InitializeComponent();

// ZoomLevel of textView is percentage based. (e.g. 20 -> 400 means 20% -> 400%)
// and the scaleFactor of CrispImage is 1 based. (e.g 1 means 100%)
var scaleFactor = textView.ZoomLevel;
var viewModel = InheritanceMarginViewModel.Create(classificationTypeMap, classificationFormatMap, tag, scaleFactor);
DataContext = viewModel;
ContextMenu.DataContext = viewModel;
Expand Down Expand Up @@ -99,6 +105,9 @@ private void InheritanceMargin_OnMouseLeave(object sender, MouseEventArgs e)
private void ContextMenu_OnClose(object sender, RoutedEventArgs e)
{
ResetBorderToInitialColor();
// Move the focus back to textView when the context menu is closed.
// It ensures the focus won't be left at the margin
ResetFocus();
}

private void ContextMenu_OnOpen(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -131,5 +140,17 @@ private void ResetBorderToInitialColor()
this.Background = Brushes.Transparent;
this.BorderBrush = Brushes.Transparent;
}

private void ResetFocus()
{
if (!_textView.HasAggregateFocus)
{
var visualElement = _textView.VisualElement;
if (visualElement.Focusable)
{
Keyboard.Focus(visualElement);
}
}
}
}
}

0 comments on commit f8d332c

Please sign in to comment.