private void AddHighlight()
        {
            // get size
            ViewTipProperty viewTip = this.textView.Get <ViewTipProperty>();

            if (viewTip == null)
            {
                return;
            }
            SnapshotPoint viewPos;

            if (!RainbowProvider.TryMapToView(this.textView, viewTip.Position, out viewPos))
            {
                return;
            }
            var line = this.textView.TextViewLines.GetTextViewLineContainingBufferPosition(viewPos);

            if (line == null)
            {
                return;
            }
            Rect rc = new Rect(
                new Point(textView.ViewportLeft, line.TextTop),
                new Point(Math.Max(textView.ViewportRight, line.TextRight), line.TextBottom)
                );

            var properties = this.formatMap.GetProperties(Rainbows.TipHilight);

            rc = CreateVisual(line.Extent, rc, properties);
        }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            RainbowProvider prov = buffer.Properties.GetOrCreateSingletonProperty(
                () => new RainbowProvider(buffer, this)
                );

            return(prov.ColorTagger as ITagger <T>);
        }
Beispiel #3
0
        private void MoveCaretTo(SnapshotPoint position)
        {
            SnapshotPoint viewPos;

            if (RainbowProvider.TryMapToView(this.textView, position, out viewPos))
            {
                this.textView.Caret.MoveTo(viewPos);
                var span = new SnapshotSpan(viewPos, 0);
                this.textView.ViewScroller.EnsureSpanVisible(span);
            }
        }
Beispiel #4
0
        public ITagger <T> CreateTagger <T>(ITextView view, ITextBuffer buffer) where T : ITag
        {
            // for a complex editor such as the HTMLX editor in VS2013
            // we need to have multiple of these created, for different text buffers
            // so this cannot be a singleton property, but we need to shim it based on
            // the buffer, not the view
            RainbowProvider prov = buffer.Properties.GetOrCreateSingletonProperty(
                () => new RainbowProvider(view, buffer, this)
                );

            return(prov.ColorTagger as ITagger <T>);
        }
Beispiel #5
0
        private void RedrawVisuals(SnapshotPoint caret, bool forceRedraw)
        {
            if (!this.provider.Settings.RainbowLinesEnabled)
            {
                this.layer.RemoveAllAdornments();
                return;
            }

            if (!RainbowProvider.TryMapPosToBuffer(this.view, caret, out caret))
            {
                this.layer.RemoveAllAdornments();
                return;
            }

            var provider = caret.Snapshot.TextBuffer.Get <RainbowProvider>();
            var braces   = provider?.BufferBraces.GetBracePairFromPosition(caret, RainbowHighlightMode.TrackInsertionPoint);

            if (braces == null)
            {
                this.currentSpan = default(SnapshotSpan);
                this.layer.RemoveAllAdornments();
                return;
            }

            SnapshotPoint opening = braces.Item1.ToPoint(caret.Snapshot);
            SnapshotPoint closing = braces.Item2.ToPoint(caret.Snapshot);

            if (RainbowProvider.TryMapToView(this.view, opening, out opening) &&
                RainbowProvider.TryMapToView(this.view, closing, out closing))
            {
                var newSpan = new SnapshotSpan(opening, closing);

                if (this.currentSpan == newSpan && !forceRedraw)
                {
                    return; // don't redraw it
                }
                this.currentSpan = default(SnapshotSpan);
                var path = CreateVisuals(opening, closing, caret);
                this.layer.RemoveAllAdornments();
                if (path != null)
                {
                    var adornment = MakeAdornment(path, braces.Item1.Depth);
                    this.layer.AddAdornment(
                        AdornmentPositioningBehavior.OwnerControlled, newSpan,
                        TAG, adornment, null
                        );

                    this.currentSpan = newSpan;
                }
            }
        }
Beispiel #6
0
        private bool MoveRainbow(bool previous, RainbowHighlightMode mode)
        {
            SnapshotPoint bufferPos;

            if (!RainbowProvider.TryMapCaretToBuffer(this.textView, out bufferPos))
            {
                return(false);
            }
            ITextBuffer     buffer   = bufferPos.Snapshot.TextBuffer;
            RainbowProvider provider = buffer.Get <RainbowProvider>();

            if (provider == null)
            {
                return(false);
            }
            var braces = provider.BufferBraces.GetBracePairFromPosition(bufferPos, mode);

            if (braces == null)
            {
                return(false);
            }
            if (previous && braces.Item1.Position == bufferPos.Position - 1)
            {
                // if we're on the opening brace, jump to the previous one
                braces = provider.BufferBraces.GetBracePairFromPosition(bufferPos - 1, mode);
            }
            else if (!previous && braces.Item2.Position == bufferPos.Position)
            {
                // if we're on the closing brace, jump to the previous one
                braces = provider.BufferBraces.GetBracePairFromPosition(bufferPos + 1, mode);
            }
            if (braces == null)
            {
                return(false);
            }
            if (previous)
            {
                SnapshotPoint opening = braces.Item1.ToPoint(bufferPos.Snapshot);
                MoveCaretTo(opening + 1);
            }
            else
            {
                SnapshotPoint closing = braces.Item2.ToPoint(bufferPos.Snapshot);
                MoveCaretTo(closing);
            }
            return(true);
        }
        private void StartRainbowHighlight(ITextView view, RainbowHighlightMode mode)
        {
            if (startedEffect)
            {
                return;
            }
            startedEffect = true;

            SnapshotPoint bufferPos;

            if (!RainbowProvider.TryMapCaretToBuffer(view, out bufferPos))
            {
                return;
            }

            ITextBuffer     buffer   = bufferPos.Snapshot.TextBuffer;
            RainbowProvider provider = buffer.Get <RainbowProvider>();

            if (provider == null)
            {
                return;
            }
            var braces = provider.BufferBraces.GetBracePairFromPosition(bufferPos, mode);

            if (braces == null)
            {
                return;
            }
            SnapshotPoint opening = braces.Item1.ToPoint(bufferPos.Snapshot);
            SnapshotPoint closing = braces.Item2.ToPoint(bufferPos.Snapshot);

            if (RainbowProvider.TryMapToView(view, opening, out opening) &&
                RainbowProvider.TryMapToView(view, closing, out closing))
            {
                RainbowHighlight highlight = RainbowHighlight.Get(view);
                if (highlight != null)
                {
                    highlight.Start(opening, closing, braces.Item1.Depth);
                }
            }
        }
#pragma warning restore 67

        public RainbowColorTagger(RainbowProvider provider)
        {
            this.provider     = provider;
            this.rainbowTags  = GetRainbows(provider.Registry, Rainbows.MaxDepth);
            this.rainbowError = provider.Registry.GetClassificationType(Rainbows.RainbowError);
        }
Beispiel #9
0
#pragma warning restore 67

        public RainbowColorTagger(RainbowProvider provider)
        {
            this.provider    = provider;
            this.rainbowTags = GetRainbows(provider.Registry, Constants.MAX_RAINBOW_DEPTH);
        }