Пример #1
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);
        }
Пример #2
0
        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);
                }
            }
        }