Ejemplo n.º 1
0
        private ReadOnlyCollection <ITagSpan <IntraTextAdornmentTag> > GetTagsCore(SnapshotSpan span)
        {
            var list     = new List <ITagSpan <IntraTextAdornmentTag> >();
            var offset   = span.Start.Position;
            var snapshot = span.Snapshot;

            for (var i = 0; i < span.Length; i++)
            {
                var position = i + offset;
                var c        = snapshot[position];

                if (!ControlCharUtil.TryGetDisplayText(c, out string text))
                {
                    continue;
                }

                UIElement adornment;
                if (TryFindIndex(position, out int cacheIndex))
                {
                    adornment = _adornmentCache[cacheIndex].Adornment;
                }
                else
                {
                    var textRunProperties = _classificationFormatMap.DefaultTextProperties;
                    var typeface          = textRunProperties.Typeface;
                    var fontSize          = textRunProperties.FontRenderingEmSize;
                    var textHeight        = _textView.LineHeight;
                    var textBlock         = new TextBlock
                    {
                        Text                 = text,
                        Foreground           = _foregroundBrush,
                        Background           = Brushes.Transparent,
                        FontFamily           = typeface.FontFamily,
                        FontStretch          = typeface.Stretch,
                        FontWeight           = typeface.Weight,
                        FontStyle            = typeface.Style,
                        FontSize             = fontSize,
                        Height               = textHeight,
                        LineHeight           = textHeight != 0 ? textHeight : double.NaN,
                        LineStackingStrategy = LineStackingStrategy.BlockLineHeight,
                        BaselineOffset       = 0,
                    };
                    textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    adornment = textBlock;
                    _adornmentCache.Insert(cacheIndex, new AdornmentData(position, adornment));
                }

                var tag           = new IntraTextAdornmentTag(adornment, null);
                var adornmentSpan = new SnapshotSpan(snapshot, position, 1);
                var tagSpan       = new TagSpan <IntraTextAdornmentTag>(adornmentSpan, tag);
                list.Add(tagSpan);
            }

            return(list.ToReadOnlyCollectionShallow());
        }
        private ReadOnlyCollection <ITagSpan <IntraTextAdornmentTag> > GetTagsCore(SnapshotSpan span)
        {
            var list     = new List <ITagSpan <IntraTextAdornmentTag> >();
            var offset   = span.Start.Position;
            var snapshot = span.Snapshot;

            for (int i = 0; i < span.Length; i++)
            {
                var position = i + offset;
                var c        = snapshot[position];

                string text;
                if (!ControlCharUtil.TryGetDisplayText(c, out text))
                {
                    continue;
                }

                UIElement adornment;
                int       cacheIndex;
                if (TryFindIndex(position, out cacheIndex))
                {
                    adornment = _adornmentCache[cacheIndex].Adornment;
                }
                else
                {
                    var textBox = new TextBox();
                    textBox.Text            = text;
                    textBox.BorderThickness = new Thickness(0);
                    textBox.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    textBox.Foreground = _foregroundBrush;
                    textBox.CaretBrush = _foregroundBrush;
                    textBox.FontWeight = FontWeights.Bold;
                    adornment          = textBox;
                    _adornmentCache.Insert(cacheIndex, new AdornmentData(position, adornment));
                }

                var tag           = new IntraTextAdornmentTag(adornment, null);
                var adornmentSpan = new SnapshotSpan(snapshot, position, 1);
                var tagSpan       = new TagSpan <IntraTextAdornmentTag>(adornmentSpan, tag);
                list.Add(tagSpan);
            }

            return(list.ToReadOnlyCollectionShallow());
        }