提交 f5620799 编写于 作者: A Ankita Khera

Hopefully fixed jitteriness

上级 248af9d6
......@@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
......@@ -18,18 +21,22 @@ namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints
internal class InlineParameterNameHintsTag : IntraTextAdornmentTag
{
public const string TagId = "inline parameter name hints";
/// <summary>
/// Creates the UIElement on call
/// Uses PositionAffinity.Predecessor because we want the tag to be associated with the preceding character
/// </summary>
/// <param name="text">The name of the parameter associated with the argument</param>
public InlineParameterNameHintsTag(string text, double lineHeight, TextFormattingRunProperties format)
: base(CreateElement(text, lineHeight, format), removalCallback: null, PositionAffinity.Predecessor)
public InlineParameterNameHintsTag(string text, IWpfTextView textView, TextFormattingRunProperties format)
: base(CreateElement(text, textView, format), removalCallback: AdornmentCallbackFunction, PositionAffinity.Predecessor)
{
}
private static void AdornmentCallbackFunction(object tag, UIElement element)
{
//
}
private static UIElement CreateElement(string text, double lineHeight, TextFormattingRunProperties format)
private static UIElement CreateElement(string text, IWpfTextView textView, TextFormattingRunProperties format)
{
// Constructs the hint block which gets assigned parameter name and fontstyles according to the options
// page. Calculates a font size 1/4 smaller than the font size of the rest of the editor
......@@ -52,13 +59,21 @@ private static UIElement CreateElement(string text, double lineHeight, TextForma
Background = format.BackgroundBrush,
Child = block,
CornerRadius = new CornerRadius(2),
Height = lineHeight - (0.25 * lineHeight),
Height = textView.LineHeight - (0.25 * textView.LineHeight),
HorizontalAlignment = HorizontalAlignment.Center,
Margin = new Thickness(0, -0.20 * lineHeight, 5, 0),
Margin = new Thickness(0, -0.20 * textView.LineHeight, 5, 0),
Padding = new Thickness(1),
VerticalAlignment = VerticalAlignment.Center,
SnapsToDevicePixels = textView.VisualElement.SnapsToDevicePixels,
UseLayoutRounding = textView.VisualElement.UseLayoutRounding,
VerticalAlignment = VerticalAlignment.Center
};
// Need to set these properties to avoid unecessary reformatting because some dependancy properties
// affect layout
TextOptions.SetTextFormattingMode(border, TextOptions.GetTextFormattingMode(textView.VisualElement));
TextOptions.SetTextHintingMode(border, TextOptions.GetTextHintingMode(textView.VisualElement));
TextOptions.SetTextRenderingMode(border, TextOptions.GetTextRenderingMode(textView.VisualElement));
border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
return border;
}
......
......@@ -24,7 +24,7 @@ internal sealed class InlineParameterNameHintsTagger : ITagger<IntraTextAdornmen
{
private readonly ITagAggregator<InlineParameterNameHintDataTag> _tagAggregator;
private readonly ITextBuffer _buffer;
private readonly ITextView _textView;
private readonly IWpfTextView _textView;
/// <summary>
/// stores the parameter hint tags in a global location
......@@ -47,7 +47,7 @@ internal sealed class InlineParameterNameHintsTagger : ITagger<IntraTextAdornmen
public event EventHandler<SnapshotSpanEventArgs>? TagsChanged;
public InlineParameterNameHintsTagger(InlineParameterNameHintsTaggerProvider taggerProvider, ITextView textView, ITextBuffer buffer, ITagAggregator<InlineParameterNameHintDataTag> tagAggregator)
public InlineParameterNameHintsTagger(InlineParameterNameHintsTaggerProvider taggerProvider, IWpfTextView textView, ITextBuffer buffer, ITagAggregator<InlineParameterNameHintDataTag> tagAggregator)
{
_cache = new List<ITagSpan<IntraTextAdornmentTag>>();
_threadAffinitizedObject = new ForegroundThreadAffinitizedObject(taggerProvider.ThreadingContext);
......@@ -118,7 +118,7 @@ public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSp
if (dataTagSpans.Count == 1)
{
var dataTagSpan = dataTagSpans[0];
_cache.Add(new TagSpan<IntraTextAdornmentTag>(new SnapshotSpan(dataTagSpan.Start, 0), new InlineParameterNameHintsTag(textTag.ParameterName, _textView.LineHeight, Format)));
_cache.Add(new TagSpan<IntraTextAdornmentTag>(new SnapshotSpan(dataTagSpan.Start, 0), new InlineParameterNameHintsTag(textTag.ParameterName, _textView, Format)));
}
}
}
......
......@@ -52,7 +52,7 @@ internal class InlineParameterNameHintsTaggerProvider : IViewTaggerProvider
}
var tagAggregator = _viewTagAggregatorFactoryService.CreateTagAggregator<InlineParameterNameHintDataTag>(textView);
return new InlineParameterNameHintsTagger(this, textView, buffer, tagAggregator) as ITagger<T>;
return new InlineParameterNameHintsTagger(this, (IWpfTextView)textView, buffer, tagAggregator) as ITagger<T>;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册