示例#1
0
        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);
        }
示例#2
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);
            }
        }
示例#3
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;
                }
            }
        }
        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);
                }
            }
        }