示例#1
0
 void InitializeOptions(bool refresh)
 {
     compressEmptyOrWhitespaceLines = textView.Options.IsCompressEmptyOrWhitespaceLinesEnabled();
     compressNonLetterLines         = textView.Options.IsCompressNonLetterLinesEnabled();
     if (refresh)
     {
         var line = textView.TextViewLines.FirstVisibleLine;
         textView.DisplayTextLineContainingBufferPosition(line.Start, line.Top - textView.ViewportTop, ViewRelativePosition.Top);
     }
 }
示例#2
0
        private void OnSettingsChanged()
        {
            SettingsStore.LoadSettings(settings);

            SetTransforms();

            var firstLine = textView.TextViewLines.FirstVisibleLine;

            textView.DisplayTextLineContainingBufferPosition(firstLine.Start,
                                                             firstLine.Top - textView.ViewportTop,
                                                             ViewRelativePosition.Top);
        }
示例#3
0
        public void EnsureVisible()
        {
            var line = ContainingTextViewLine;

            if (line.VisibilityState != VisibilityState.FullyVisible)
            {
                ViewRelativePosition relativeTo;
                var firstVisibleLine = textView.TextViewLines?.FirstVisibleLine;
                if (firstVisibleLine == null || !firstVisibleLine.IsVisible())
                {
                    relativeTo = ViewRelativePosition.Top;
                }
                else if (line.Start.Position <= firstVisibleLine.Start.Position)
                {
                    relativeTo = ViewRelativePosition.Top;
                }
                else
                {
                    relativeTo = ViewRelativePosition.Bottom;
                }
                textView.DisplayTextLineContainingBufferPosition(line.Start, 0, relativeTo);
            }

            double left  = textCaretLayer.Left;
            double right = textCaretLayer.Right;

            double availWidth = Math.Max(0, textView.ViewportWidth - textCaretLayer.Width);
            double extraScroll;

            if (availWidth >= WpfTextViewConstants.EXTRA_HORIZONTAL_WIDTH)
            {
                extraScroll = WpfTextViewConstants.EXTRA_HORIZONTAL_WIDTH;
            }
            else
            {
                extraScroll = availWidth / 2;
            }
            if (textView.ViewportWidth == 0)
            {
                // Don't do anything if there's zero width. This can happen during
                // startup when code accesses the caret before the window is shown.
            }
            else if (left < textView.ViewportLeft)
            {
                textView.ViewportLeft = left - extraScroll;
            }
            else if (right > textView.ViewportRight)
            {
                textView.ViewportLeft = right + extraScroll - textView.ViewportWidth;
            }
        }
示例#4
0
        private void OnOptionChanged(object sender, EditorOptionChangedEventArgs e)
        {
            if ((e.OptionId == SyntacticFisheyeCompressBlankLines.StaticName) || (e.OptionId == SyntacticFisheyeCompressSimpleLines.StaticName))
            {
                _compressBlankLines  = _view.Options.GetOptionValue(SyntacticFisheyeCompressBlankLines.StaticKey);
                _compressSimpleLines = _view.Options.GetOptionValue(SyntacticFisheyeCompressSimpleLines.StaticKey);

                if (!(_view.IsClosed || _view.InLayout))
                {
                    var firstLine = _view.TextViewLines.FirstVisibleLine;
                    _view.DisplayTextLineContainingBufferPosition(firstLine.Start, firstLine.Top - _view.ViewportTop, ViewRelativePosition.Top);
                }
            }
        }
示例#5
0
        /// <summary>
        /// The caret has been moved by the user. Update line transformations to reflect new position
        /// </summary>
        private void OnCaretChanged(object sender, CaretPositionChangedEventArgs args)
        {
            //Did the caret line number change?
            SnapshotPoint oldPosition = args.OldPosition.BufferPosition;
            SnapshotPoint newPosition = args.NewPosition.BufferPosition;

            if (_textView.TextSnapshot.GetLineNumberFromPosition(newPosition) != _textView.TextSnapshot.GetLineNumberFromPosition(oldPosition))
            {
                //Yes. Is the caret on a line that has been formatted by the view?
                ITextViewLine line = _textView.Caret.ContainingTextViewLine;
                if (line.VisibilityState != VisibilityState.Unattached)
                {
                    //Yes. Force the view to redraw so that (top of) the caret line has exactly the same position.
                    _textView.DisplayTextLineContainingBufferPosition(line.Start, line.Top, ViewRelativePosition.Top);
                }
            }
        }
        private void RequestRedrawLine(int lineNo)
        {
            try
            {
                foreach (var line in m_view.TextSnapshot.Lines)
                {
                    int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
                    if (lineNo == lineNumber)
                    {
                        m_view.DisplayTextLineContainingBufferPosition(line.Start, 0.0, ViewRelativePosition.Top);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Notify(ex, true);
            }

            // RequestRedrawView();

            /* foreach (ITextViewLine line in this.m_view.TextViewLines)
             * {
             *  m_view.DisplayTextLineContainingBufferPosition(line.Start, line.Top, ViewRelativePosition.Top);
             *  // int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
             *  // m_editedLines[lineNumber] = line;            // #Image _editedLines[lineNumber] = line
             * } */

            // ResetTimer();

            /* try
             * {
             *  IWpfTextViewLineCollection textViewLines = this.m_view.TextViewLines;
             *  foreach (var line in this.m_view.TextViewLines)
             *  {
             *      int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
             *      if(lineNo == lineNumber)
             *      {
             *          m_view.DisplayTextLineContainingBufferPosition(line.Start, line.Top, ViewRelativePosition.Top);
             *      }
             *  }
             * }
             * catch (Exception ex)
             * {
             *  ExceptionHandler.Notify(ex, true);
             * } */
        }
示例#7
0
        public void ScrollTo(double track_y)
        {
            var snapshot = _view.VisualSnapshot;

            int line_number = GetLineFromPosition(track_y - ThumbHeight / 2);

            line_number = Math.Max(line_number, 0);
            line_number = Math.Min(line_number, snapshot.LineCount - 1);

            var line = snapshot.GetLineFromLineNumber(line_number);
            var p    = _view.BufferGraph.MapDownToBuffer(line.Start, PointTrackingMode.Negative, _view.TextBuffer, PositionAffinity.Predecessor);

            if (p.HasValue)
            {
                _view.DisplayTextLineContainingBufferPosition(p.Value.GetContainingLine().Start, 0, ViewRelativePosition.Top);
            }
        }
        int IOleCommandTarget.Exec(ref Guid commandGroupId, uint commandId, uint executeInformation, IntPtr inVar, IntPtr outVar)
        {
            if (commandGroupId == Guids.CommandSetId)
            {
                switch (commandId)
                {
                case CommandIDs.ImplementNotifyPropertyChangedCommandId:
                    // TODO: Wrap in undo transaction

                    IEnumerable <SyntaxAnnotation> propertyAnnotations;
                    var newCompUnit = Implementer.Apply(GetText(), GetSelectionSpan(), out propertyAnnotations);

                    // Store the top line number in view so we can reset it afterwards
                    var topLineNumber = wpfTextView.TextViewLines.FirstVisibleLine.Start.GetContainingLine().LineNumber;

                    var buffer = wpfTextView.TextBuffer;
                    buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), newCompUnit.ToString());

                    var snapshot = buffer.CurrentSnapshot;

                    var annotatedProperties = propertyAnnotations.Select(annotation => newCompUnit.GetAnnotatedNode <PropertyDeclarationSyntax>(annotation));

                    // Create tracking points from the start of the first property that we expanded to the end of the last property.
                    var selectionStart = snapshot.CreateTrackingPoint(annotatedProperties.First().Span.Start, PointTrackingMode.Negative);
                    var selectionEnd   = snapshot.CreateTrackingPoint(annotatedProperties.Last().Span.End, PointTrackingMode.Positive);

                    FormatDocument();

                    // After formatting, use our tracking points to select the expanded properties
                    var formattedSnapshot = buffer.CurrentSnapshot;
                    wpfTextView.Selection.Select(
                        new VirtualSnapshotPoint(selectionStart.GetPoint(formattedSnapshot)),
                        new VirtualSnapshotPoint(selectionEnd.GetPoint(formattedSnapshot)));

                    // Reset the top line in view
                    var topLine = formattedSnapshot.GetLineFromLineNumber(topLineNumber);
                    wpfTextView.DisplayTextLineContainingBufferPosition(topLine.Start, 0.0, ViewRelativePosition.Top);

                    return(VSConstants.S_OK);
                }
            }

            return(nextCommandTarget.Exec(ref commandGroupId, commandId, executeInformation, inVar, outVar));
        }
示例#9
0
 /// <summary>
 /// Handles the click event on a tag
 /// </summary>
 private void Adornment_TagClicked(CBAdornmentData adornment, bool jumpToHead)
 {
     if (_TextView != null)
     {
         SnapshotPoint targetPoint = new SnapshotPoint();
         if (jumpToHead)
         {
             // Jump to header
             targetPoint = new SnapshotPoint(_TextView.TextBuffer.CurrentSnapshot, adornment.HeaderStartPosition);
             _TextView.DisplayTextLineContainingBufferPosition(targetPoint, 30, ViewRelativePosition.Top);
         }
         else
         {
             // Set caret behind closing bracet
             targetPoint = new SnapshotPoint(_TextView.TextBuffer.CurrentSnapshot, adornment.EndPosition + 1);
         }
         _TextView.Caret.MoveTo(targetPoint);
     }
 }
示例#10
0
        private void ScrollViewToYCoordinate(double y)
        {
            double yLastLine = _scrollBar.TrackSpanBottom;

            if (y < yLastLine)
            {
                SnapshotPoint position = _scrollBar.GetBufferPositionOfYCoordinate(y);

                _textView.ViewScroller.EnsureSpanVisible(new SnapshotSpan(position, 0), EnsureSpanVisibleOptions.AlwaysCenter);
            }
            else
            {
                y = Math.Min(y, yLastLine + (_scrollBar.ThumbHeight / 2.0));
                double fraction = (y - yLastLine) / _scrollBar.ThumbHeight;               // 0 to 0.5
                double dyDistanceFromTopOfViewport = _textView.ViewportHeight * (0.5 - fraction);
                var    end = new SnapshotPoint(_textView.TextSnapshot, _textView.TextSnapshot.Length);

                _textView.DisplayTextLineContainingBufferPosition(end, dyDistanceFromTopOfViewport, ViewRelativePosition.Top);
            }
        }
        private void OnHighlightRequested(object sender, HighlightRequestedEventArgs e)
        {
            var node = e.NodeContainer;

            if (node == null)
            {
                return;
            }

            var startLine    = _textView.TextSnapshot.GetLineFromLineNumber(node.StartLineNumber);
            var endLine      = _textView.TextSnapshot.GetLineFromLineNumber(node.EndLineNumber);
            var snapshotSpan = new SnapshotSpan(startLine.Start, endLine.End);

            _textView.DisplayTextLineContainingBufferPosition(snapshotSpan.Start, 30, ViewRelativePosition.Top);

            // get start and end of snapshot
            var lines = _textView.TextViewLines.GetTextViewLinesIntersectingSpan(snapshotSpan);

            if (lines.Count == 0)
            {
                return;
            }

            // clear adornments
            _adornmentLayer.RemoveAdornmentsByTag(HighlightAdornmentTag);

            // create new adornment
            var start          = _textView.GetTextViewLineContainingBufferPosition(startLine.Start);
            var end            = _textView.GetTextViewLineContainingBufferPosition(endLine.End);
            var adornerContent = new SelectionHintControl();

            Canvas.SetTop(adornerContent, start.Top);
            Canvas.SetLeft(adornerContent, 0);

            adornerContent.Height = Math.Max(start.Height, end.Top - start.Top);

            adornerContent.Width = Math.Max(0, _textView.ViewportWidth);
            _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.OwnerControlled, null, HighlightAdornmentTag, adornerContent, null);
        }
        void OnScroll(ScrollDirection value, double xCoordinate)
        {
            ITextViewLine line;
            SnapshotPoint lineStart;

            switch (value)
            {
            case ScrollDirection.Left:
                line = wpfTextView.Caret.ContainingTextViewLine;
                if (line.TextLeft >= wpfTextView.ViewportLeft)
                {
                    StopScrolling();
                }
                else if (wpfTextView.Caret.InVirtualSpace || wpfTextView.Caret.Position.BufferPosition != line.Start)
                {
                    editorOperations.MoveToPreviousCharacter(true);
                }
                else
                {
                    wpfTextView.ViewportLeft = line.TextLeft;
                    StopScrolling();
                }
                break;

            case ScrollDirection.Right:
                line = wpfTextView.Caret.ContainingTextViewLine;
                if (line.TextRight <= wpfTextView.ViewportRight)
                {
                    StopScrolling();
                }
                else if (wpfTextView.Caret.InVirtualSpace || wpfTextView.Caret.Position.BufferPosition < line.End)
                {
                    editorOperations.MoveToNextCharacter(true);
                }
                else
                {
                    wpfTextView.ViewportLeft = Math.Max(0, line.TextRight - wpfTextView.ViewportWidth);
                    StopScrolling();
                }
                break;

            case ScrollDirection.Up:
                line = wpfTextView.TextViewLines.FirstVisibleLine;
                if (line.VisibilityState == VisibilityState.FullyVisible && !line.IsFirstDocumentLine())
                {
                    line = wpfTextView.GetTextViewLineContainingBufferPosition(line.Start - 1);
                }
                lineStart = line.Start;
                if (line.VisibilityState != VisibilityState.FullyVisible)
                {
                    wpfTextView.DisplayTextLineContainingBufferPosition(line.Start, 0, ViewRelativePosition.Top);
                }
                if (!line.IsValid)
                {
                    line = wpfTextView.GetTextViewLineContainingBufferPosition(lineStart);
                }
                if (line.IsFirstDocumentLine())
                {
                    StopScrolling();
                }
                editorOperations.MoveCaret(line, xCoordinate, true);
                break;

            case ScrollDirection.Down:
                line = wpfTextView.TextViewLines.LastVisibleLine;
                if (line.VisibilityState == VisibilityState.FullyVisible && !line.IsLastDocumentLine())
                {
                    line = wpfTextView.GetTextViewLineContainingBufferPosition(line.GetPointAfterLineBreak());
                }
                lineStart = line.Start;
                if (line.VisibilityState != VisibilityState.FullyVisible)
                {
                    wpfTextView.DisplayTextLineContainingBufferPosition(line.Start, 0, ViewRelativePosition.Bottom);
                }
                if (!line.IsValid)
                {
                    line = wpfTextView.GetTextViewLineContainingBufferPosition(lineStart);
                }
                if (line.IsLastDocumentLine())
                {
                    StopScrolling();
                }
                editorOperations.MoveCaret(line, xCoordinate, true);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(value));
            }

            wpfTextView.Caret.EnsureVisible();
        }
示例#13
0
        private void OnTimerElapsed(object sender, EventArgs e)
        {
            if ((!_view.IsClosed) && (_view.VisualElement.IsVisible) && _location.HasValue)
            {
                DateTime now = DateTime.Now;

                Point currentPosition = _view.VisualElement.PointToScreen(Mouse.GetPosition(_view.VisualElement));

                var delta = currentPosition - _location.Value;

                double absDeltaX = Math.Abs(delta.X);
                double absDeltaY = Math.Abs(delta.Y);

                double maxDelta = Math.Max(absDeltaX, absDeltaY);
                if (maxDelta > minMove)
                {
                    _dismissOnMouseUp = true;

                    double deltaT = (now - _lastMoveTime).TotalMilliseconds;
                    double pixels = (maxDelta - minMove) * deltaT / moveDivisor;

                    if (absDeltaX > absDeltaY)
                    {
                        if (delta.X > 0.0)
                        {
                            _view.ViewportLeft        += pixels;
                            _view.VisualElement.Cursor = Cursors.ScrollE;
                        }
                        else
                        {
                            _view.ViewportLeft        -= pixels;
                            _view.VisualElement.Cursor = Cursors.ScrollW;
                        }
                    }
                    else
                    {
                        ITextViewLine top       = _view.TextViewLines[0];
                        double        newOffset = top.Top - _view.ViewportTop;
                        if (delta.Y > 0.0)
                        {
                            newOffset = (newOffset - pixels);
                            _view.VisualElement.Cursor = Cursors.ScrollS;
                        }
                        else
                        {
                            newOffset = (newOffset + pixels);
                            _view.VisualElement.Cursor = Cursors.ScrollN;
                        }

                        _view.DisplayTextLineContainingBufferPosition(top.Start, newOffset, ViewRelativePosition.Top);
                    }
                }
                else
                {
                    _view.VisualElement.Cursor = Cursors.ScrollAll;
                }

                _lastMoveTime = now;
            }
            else
            {
                this.StopScrolling();
            }
        }