예제 #1
0
        // Strange things:
        // If a Peek-Definition window is opened, and the user
        // holds the key down on it, the main textview will
        // get the event, instead of the embedded window.
        //
        // I guess I'm probably doing something wrong,
        // such as not marking up this key processor correctly
        // so that the embedded window gets the event,
        // but for now, just use the event source
        // as a work around.
        public override void PreviewKeyDown(KeyEventArgs args)
        {
            ITextView actualView = GetViewFromEvent(args);

            if (args.Key == (Key)(this.settings.RainbowHighlightKey))
            {
                if (this.timer.IsRunning)
                {
                    if (this.timer.Elapsed >= this.pressTime)
                    {
                        this.timer.Stop();
                        RainbowHighlightMode mode = this.settings.RainbowHighlightMode;
                        StartRainbowHighlight(actualView, mode);
                    }
                }
                else
                {
                    this.timer.Start();
                }
            }
            else
            {
                this.timer.Stop();
            }
        }
예제 #2
0
        // Strange things:
        // If a Peek-Definition window is opened, and the user
        // holds the key down on it, the main textview will
        // get the event, instead of the embedded window.
        //
        // I guess I'm probably doing something wrong,
        // such as not marking up this key processor correctly
        // so that the embedded window gets the event,
        // but for now, just use the event source
        // as a work around.
        public override void PreviewKeyDown(KeyEventArgs args)
        {
            ITextView actualView = GetViewFromEvent(args);

            if (args.Key == Key.LeftCtrl)
            {
                if (timer.IsRunning)
                {
                    if (timer.Elapsed >= pressTime)
                    {
                        timer.Stop();
                        RainbowHighlightMode mode = VsfSettings.RainbowHighlightMode;
                        StartRainbowHighlight(actualView, mode);
                    }
                }
                else
                {
                    timer.Start();
                }
            }
            else
            {
                timer.Stop();
            }
        }
예제 #3
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);
        }
예제 #4
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);
                }
            }
        }
예제 #5
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.BraceCache.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);
            }
              }
        }
예제 #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;
 }
예제 #7
0
        public Tuple <BracePos, BracePos> GetBracePairFromPosition(SnapshotPoint point, RainbowHighlightMode mode)
        {
            if (point.Snapshot != this.Snapshot || point.Position >= Snapshot.Length)
            {
                return(null);
            }

            this.EnsureLinesInPreferredSpan(point.SpanUntil());

            int      openIndex = -1;
            BracePos?opening   = null;

            if (mode == RainbowHighlightMode.TrackInsertionPoint)
            {
                opening = FindClosestOpeningBrace(point.Position, out openIndex);
            }
            else
            {
                opening = CheckForBraceAtPositionOrClosestOpeningBrace(point.Position, out openIndex);
            }
            if (opening == null)
            {
                return(null);
            }

            for (int i = openIndex + 1; i < this.braces.Count; i++)
            {
                if (i == this.braces.Count - 1)
                {
                    // continue parsing the document if necessary
                    this.ContinueParsing(this.LastParsedPosition, this.Snapshot.Length);
                }
                BracePos closing = this.braces[i];
                if (this.IsOpeningBrace(closing.Brace))
                {
                    continue;
                }
                if (this.braceList[opening.Value.Brace] == closing.Brace &&
                    closing.Depth == opening.Value.Depth)
                {
                    return(new Tuple <BracePos, BracePos>(opening.Value, closing));
                }
            }
            return(null);
        }
예제 #8
0
        public Tuple<BracePos, BracePos> GetBracePairFromPosition(SnapshotPoint point, RainbowHighlightMode mode)
        {
            if ( point.Snapshot != this.Snapshot || point.Position >= Snapshot.Length ) {
            return null;
              }

              int openIndex = -1;
              BracePos? opening = null;

              if ( mode == RainbowHighlightMode.TrackInsertionPoint ) {
            opening = FindClosestOpeningBrace(point.Position, out openIndex);
              } else {
            opening = CheckForBraceAtPositionOrClosestOpeningBrace(point.Position, out openIndex);
              }
              if ( opening == null ) {
            return null;
              }

              for ( int i = openIndex + 1; i < this.braces.Count; i++ ) {
            if ( i == this.braces.Count - 1 ) {
              // continue parsing the document if necessary
              this.ContinueParsing(this.LastParsedPosition, this.Snapshot.Length);
            }
            BracePos closing = this.braces[i];
            if ( this.IsOpeningBrace(closing.Brace) )
              continue;
            if ( this.braceList[opening.Value.Brace] == closing.Brace
            && closing.Depth == opening.Value.Depth ) {
              return new Tuple<BracePos, BracePos>(opening.Value, closing);
            }
              }
              return null;
        }