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

Hopefully fixed jitteriness

上级 248af9d6
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // 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;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
...@@ -18,18 +21,22 @@ namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints ...@@ -18,18 +21,22 @@ namespace Microsoft.CodeAnalysis.Editor.InlineParameterNameHints
internal class InlineParameterNameHintsTag : IntraTextAdornmentTag internal class InlineParameterNameHintsTag : IntraTextAdornmentTag
{ {
public const string TagId = "inline parameter name hints"; public const string TagId = "inline parameter name hints";
/// <summary> /// <summary>
/// Creates the UIElement on call /// Creates the UIElement on call
/// Uses PositionAffinity.Predecessor because we want the tag to be associated with the preceding character /// Uses PositionAffinity.Predecessor because we want the tag to be associated with the preceding character
/// </summary> /// </summary>
/// <param name="text">The name of the parameter associated with the argument</param> /// <param name="text">The name of the parameter associated with the argument</param>
public InlineParameterNameHintsTag(string text, double lineHeight, TextFormattingRunProperties format) public InlineParameterNameHintsTag(string text, IWpfTextView textView, TextFormattingRunProperties format)
: base(CreateElement(text, lineHeight, format), removalCallback: null, PositionAffinity.Predecessor) : 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 // 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 // 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 ...@@ -52,13 +59,21 @@ private static UIElement CreateElement(string text, double lineHeight, TextForma
Background = format.BackgroundBrush, Background = format.BackgroundBrush,
Child = block, Child = block,
CornerRadius = new CornerRadius(2), CornerRadius = new CornerRadius(2),
Height = lineHeight - (0.25 * lineHeight), Height = textView.LineHeight - (0.25 * textView.LineHeight),
HorizontalAlignment = HorizontalAlignment.Center, 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), 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)); border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
return border; return border;
} }
......
...@@ -24,7 +24,7 @@ internal sealed class InlineParameterNameHintsTagger : ITagger<IntraTextAdornmen ...@@ -24,7 +24,7 @@ internal sealed class InlineParameterNameHintsTagger : ITagger<IntraTextAdornmen
{ {
private readonly ITagAggregator<InlineParameterNameHintDataTag> _tagAggregator; private readonly ITagAggregator<InlineParameterNameHintDataTag> _tagAggregator;
private readonly ITextBuffer _buffer; private readonly ITextBuffer _buffer;
private readonly ITextView _textView; private readonly IWpfTextView _textView;
/// <summary> /// <summary>
/// stores the parameter hint tags in a global location /// stores the parameter hint tags in a global location
...@@ -47,7 +47,7 @@ internal sealed class InlineParameterNameHintsTagger : ITagger<IntraTextAdornmen ...@@ -47,7 +47,7 @@ internal sealed class InlineParameterNameHintsTagger : ITagger<IntraTextAdornmen
public event EventHandler<SnapshotSpanEventArgs>? TagsChanged; 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>>(); _cache = new List<ITagSpan<IntraTextAdornmentTag>>();
_threadAffinitizedObject = new ForegroundThreadAffinitizedObject(taggerProvider.ThreadingContext); _threadAffinitizedObject = new ForegroundThreadAffinitizedObject(taggerProvider.ThreadingContext);
...@@ -118,7 +118,7 @@ public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSp ...@@ -118,7 +118,7 @@ public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSp
if (dataTagSpans.Count == 1) if (dataTagSpans.Count == 1)
{ {
var dataTagSpan = dataTagSpans[0]; 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 ...@@ -52,7 +52,7 @@ internal class InlineParameterNameHintsTaggerProvider : IViewTaggerProvider
} }
var tagAggregator = _viewTagAggregatorFactoryService.CreateTagAggregator<InlineParameterNameHintDataTag>(textView); 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.
先完成此消息的编辑!
想要评论请 注册