Esempio n. 1
0
 public SnapshotSpan GetSpan(ITextSnapshot snapshot)
 {
     return(new SnapshotSpan(
                snapshot,
                Span.FromBounds(_start.GetPoint(snapshot), _end.GetPoint(snapshot))
                ));
 }
Esempio n. 2
0
 private void UpdateSelection()
 {
     if (this.IsActive)
     {
         var currentPosition = this.view.GetCaretPosition();
         this.view.Selection.Select(new VirtualSnapshotPoint(currentMark.GetPoint(this.view.TextSnapshot)), new VirtualSnapshotPoint(currentPosition));
         this.view.Caret.EnsureVisible();
     }
 }
Esempio n. 3
0
 private void UpdateSelection()
 {
     if (!IsActive)
     {
         return;
     }
     view.Selection.Select(new VirtualSnapshotPoint(currentMark.GetPoint(view.TextSnapshot)),
                           new VirtualSnapshotPoint(view.GetCaretPosition()));
     view.Caret.EnsureVisible();
 }
Esempio n. 4
0
        public void Start()
        {
            // On a background thread, perform our typing work.
            ThreadPool.QueueUserWorkItem((state) =>
            {
                Random random = new Random();

                for (int i = 0; i < _textToType.Length; i++)
                {
                    // Dispatch back to the UI thread to make the edit on the buffer
                    _dispatcher.Invoke(new Action(() =>
                    {
                        ITextSnapshot snapshot       = _insertionPoint.TextBuffer.CurrentSnapshot;
                        SnapshotPoint insertionPoint = _insertionPoint.GetPoint(snapshot);

                        if (i == 0)
                        {
                            CaptureInsertionSpan(insertionPoint);
                        }

                        snapshot.TextBuffer.Insert(insertionPoint, _textToType.Substring(i, 1));
                    }), DispatcherPriority.Normal);

                    // Between each typing action, sleep for a little while
                    Thread.Sleep(50 + random.Next(200));
                }
            });
        }
Esempio n. 5
0
        void PerformActionInUndo(Func <bool> action)
        {
            ITrackingPoint    anchor = _textView.TextSnapshot.CreateTrackingPoint(_textView.Selection.AnchorPoint.Position, PointTrackingMode.Positive);
            ITrackingPoint    active = _textView.TextSnapshot.CreateTrackingPoint(_textView.Selection.ActivePoint.Position, PointTrackingMode.Positive);
            bool              empty  = _textView.Selection.IsEmpty;
            TextSelectionMode mode   = _textView.Selection.Mode;

            using (var undo = _undoHistory.CreateTransaction("Untabify"))
            {
                _operations.AddBeforeTextBufferChangePrimitive();

                if (!action())
                {
                    undo.Cancel();
                    return;
                }

                ITextSnapshot after = _textView.TextSnapshot;

                _operations.SelectAndMoveCaret(new VirtualSnapshotPoint(anchor.GetPoint(after)),
                                               new VirtualSnapshotPoint(active.GetPoint(after)),
                                               mode,
                                               EnsureSpanVisibleOptions.ShowStart);

                _operations.AddAfterTextBufferChangePrimitive();

                undo.Complete();
            }
        }
        private void DrawSingleSyncPoint(ITrackingPoint trackPoint)
        {
            if (trackPoint.GetPosition(m_textView.TextSnapshot) >= m_textView.TextSnapshot.Length)
            {
                return;
            }

            SnapshotSpan    span    = new SnapshotSpan(trackPoint.GetPoint(m_textView.TextSnapshot), 1);
            var             brush   = Brushes.DarkGray;
            var             geom    = m_textView.TextViewLines.GetLineMarkerGeometry(span);
            GeometryDrawing drawing = new GeometryDrawing(brush, null, geom);

            if (drawing.Bounds.IsEmpty)
            {
                return;
            }

            Rectangle rect = new Rectangle()
            {
                Fill   = brush,
                Width  = drawing.Bounds.Width / 6,
                Height = drawing.Bounds.Height - 4,
                Margin = new System.Windows.Thickness(0, 2, 0, 0),
            };

            Canvas.SetLeft(rect, geom.Bounds.Left);
            Canvas.SetTop(rect, geom.Bounds.Top);
            m_adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "MultiEditLayer", rect, null);
        }
Esempio n. 7
0
        /// <summary>
        /// Draw a caret in its position
        /// </summary>
        /// <param name="curTrackPoint"></param>
        /// <param name="brush"></param>
        private void DrawSingleSyncPoint(ITrackingPoint curTrackPoint, SolidColorBrush brush)
        {
            SnapshotSpan  span;
            SnapshotPoint tempSnapPoint = curTrackPoint.GetPoint(m_textView.TextSnapshot);

            if (tempSnapPoint.Position != m_textView.TextSnapshot.Length)
            {
                //m_textView.TextSnapshot.TextBuffer.Insert(tempSnapPoint.Position, " ");
                //tempSnapPoint = tempSnapPoint.Subtract(1);
                span = new SnapshotSpan(tempSnapPoint, 1);
                var             g       = m_textView.TextViewLines.GetLineMarkerGeometry(span);
                GeometryDrawing drawing = new GeometryDrawing(brush, null, g);
                if (drawing.Bounds.IsEmpty)
                {
                    return;
                }

                System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle()
                {
                    Fill   = brush,
                    Width  = drawing.Bounds.Width / 4,
                    Height = drawing.Bounds.Height
                };
                Canvas.SetLeft(r, g.Bounds.Left);
                Canvas.SetTop(r, g.Bounds.Top);
                m_adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "MultiEditLayer", r, null);
            }
        }
Esempio n. 8
0
        Tuple <IWpfTextViewLine, SnapshotPoint> GetTriggerLine()
        {
            var point = trackingPoint.GetPoint(wpfTextView.TextSnapshot);
            var line  = wpfTextView.TextViewLines.GetTextViewLineContainingBufferPosition(point);

            return(line == null ? null : Tuple.Create(line, point));
        }
        private void DrawCaret(ITrackingPoint caretPoint)
        {
            if (caretPoint.GetPosition(Snapshot) >= Snapshot.Length)
            {
                return;
            }

            var      span     = new SnapshotSpan(caretPoint.GetPoint(Snapshot), 1);
            Geometry geometry = view.TextViewLines.GetTextMarkerGeometry(span);

            if (geometry != null)
            {
                var drawing = new GeometryDrawing(
                    caretBrush,
                    null,
                    geometry
                    );

                Rectangle rectangle = new Rectangle()
                {
                    Fill   = caretBrush,
                    Width  = drawing.Bounds.Width / 6,
                    Height = drawing.Bounds.Height,
                    Margin = new System.Windows.Thickness(0, 0, 0, 0),
                };

                Canvas.SetLeft(rectangle, geometry.Bounds.Left);
                Canvas.SetTop(rectangle, geometry.Bounds.Top);

                layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "SelectNextOccurrence", rectangle, null);
            }
        }
        private LinePosition GetLinePosition(ITextSnapshot snapshot, ITrackingPoint trackingPoint)
        {
            var point = trackingPoint.GetPoint(snapshot);
            var line  = point.GetContainingLine();

            return(new LinePosition(line.LineNumber, point.Position - line.Start));
        }
Esempio n. 11
0
        private ITrackingPoint PointToViewBuffer(ITextView textView, ITrackingPoint trackingPoint)
        {
            // Requires UI thread for BufferGraph.
            IntellisenseUtilities.ThrowIfNotOnMainThread(this.joinableTaskContext);

            if ((trackingPoint == null) || (textView.TextBuffer == trackingPoint.TextBuffer))
            {
                return(trackingPoint);
            }

            var targetSnapshot  = textView.TextSnapshot;
            var point           = trackingPoint.GetPoint(trackingPoint.TextBuffer.CurrentSnapshot);
            var viewBufferPoint = textView.BufferGraph.MapUpToSnapshot(
                point,
                trackingPoint.TrackingMode,
                PositionAffinity.Predecessor,
                targetSnapshot);

            if (viewBufferPoint == null)
            {
                return(null);
            }

            return(targetSnapshot.CreateTrackingPoint(
                       viewBufferPoint.Value.Position,
                       trackingPoint.TrackingMode));
        }
Esempio n. 12
0
        private void DrawSinglePoint(ITrackingPoint trackingPoint)
        {
            if (trackingPoint.GetPosition(_view.TextSnapshot) >= _view.TextSnapshot.Length)
            {
                return;
            }

            SnapshotSpan span = new SnapshotSpan(trackingPoint.GetPoint(_view.TextSnapshot), 1);

            SolidColorBrush brush = Brushes.Black;

            Geometry geometry = _view.TextViewLines.GetLineMarkerGeometry(span);

            GeometryDrawing drawing = new GeometryDrawing(brush, null, geometry);

            if (drawing.Bounds.IsEmpty)
            {
                return;
            }

            Rectangle rectangle = new Rectangle()
            {
                Fill  = brush,
                Width = drawing.Bounds.Width / 6,
                //Height = drawing.Bounds.Height - 4,
                Height = drawing.Bounds.Height - 2,
                Margin = new System.Windows.Thickness(0, 2, 0, 0),
            };

            Canvas.SetLeft(rectangle, geometry.Bounds.Left);
            Canvas.SetTop(rectangle, geometry.Bounds.Top);

            _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "NextOcurrence", rectangle, null);
        }
Esempio n. 13
0
 public SnapshotPoint?GetPoint(ITextSnapshot targetSnapshot, PositionAffinity affinity)
 {
     try {
         return(_trackingPoint.GetPoint(targetSnapshot));
     } catch (ArgumentException) {
         return(null);
     }
 }
Esempio n. 14
0
        internal void SwapPointAndMark()
        {
            ITrackingPoint trackingPoint = activeMark;

            activeMark = currentMark = CreateTrackingPoint(view.GetCaretPosition());
            view.Caret.MoveTo(trackingPoint.GetPoint(view.TextSnapshot));
            IsActive = true;
            UpdateSelection();
        }
Esempio n. 15
0
        public static bool CanMapDownToBuffer(ITextView textView, ITextBuffer textBuffer, ITrackingPoint triggerPoint)
        {
            SnapshotPoint triggerSnapshotPoint = triggerPoint.GetPoint(textView.TextSnapshot);
            var           triggerSpan          = new SnapshotSpan(triggerSnapshotPoint, 0);

            var mappedSpans = new FrugalList <SnapshotSpan>();

            MappingHelper.MapDownToBufferNoTrack(triggerSpan, textBuffer, mappedSpans);
            return(mappedSpans.Count > 0);
        }
		public static SnapshotPoint? GetTriggerPoint(ITextView textView, ITrackingPoint triggerPoint, ITextSnapshot textSnapshot) {
			if (textView == null)
				throw new ArgumentNullException(nameof(textView));
			if (triggerPoint == null)
				throw new ArgumentNullException(nameof(triggerPoint));
			if (textSnapshot == null)
				throw new ArgumentNullException(nameof(textSnapshot));

			return triggerPoint.GetPoint(textView.TextSnapshot);
		}
Esempio n. 17
0
 public int EndCurrentExpansion(bool leaveCaret)
 {
     if (_endCaretPoint != null)
     {
         _textView.Selection.Clear();
         _textView.Caret.MoveTo(_endCaretPoint.GetPoint(_textView.TextBuffer.CurrentSnapshot));
         return(_session.EndCurrentExpansion(1));
     }
     return(_session.EndCurrentExpansion(leaveCaret ? 1 : 0));
 }
        private bool IsSingleLine(ITrackingPoint openingPoint, ITrackingPoint closingPoint)
        {
            if (openingPoint != null && closingPoint != null)
            {
                ITextSnapshot snapshot = openingPoint.TextBuffer.CurrentSnapshot;

                return(openingPoint.GetPoint(snapshot).GetContainingLine().End.Position >= closingPoint.GetPoint(snapshot).Position);
            }

            return(false);
        }
Esempio n. 19
0
 public SnapshotPoint?GetTriggerPoint(ITextSnapshot textSnapshot)
 {
     if (!IsStarted)
     {
         throw new InvalidOperationException();
     }
     if (IsDismissed)
     {
         throw new InvalidOperationException();
     }
     return(triggerPoint.GetPoint(textSnapshot));
 }
            public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
            {
                ITextSnapshot  snapshot     = _buffer.CurrentSnapshot;
                ITrackingPoint triggerPoint = session.GetTriggerPoint(_buffer);
                SnapshotPoint  point        = triggerPoint.GetPoint(snapshot);

                SyntaxTree syntax            = snapshot.GetSyntaxTree();
                RobotsTxtDocumentSyntax root = syntax.Root as RobotsTxtDocumentSyntax;

                applicableToSpan = null;

                // find section
                RobotsTxtLineSyntax line = root.Records
                                           .SelectMany(r => r.Lines)
                                           .FirstOrDefault(s => s.NameToken.Span.Span.Contains(point));

                if (line != null)
                {
                    IClassificationFormatMap formatMap = _classificationFormatMapService.GetClassificationFormatMap(session.TextView);

                    string fieldName = line.NameToken.Value;

                    // get glyph
                    var glyph = _glyphService.GetGlyph(StandardGlyphGroup.GlyphGroupProperty, StandardGlyphItem.GlyphItemPublic);
                    var classificationType = _classificationRegistry.GetClassificationType("RobotsTxt/RecordName");
                    var format             = formatMap.GetTextProperties(classificationType);

                    // construct content
                    ISemanticModel model = syntax.GetSemanticModel();
                    var            field = model.GetFieldSymbol(line);

                    var content = new QuickInfoContent
                    {
                        Glyph     = glyph,
                        Signature = new Run(field.Name)
                        {
                            Foreground = format.ForegroundBrush
                        },
                        Documentation = RobotsTxtDocumentation.GetDocumentation(field),
                    };

                    // add to session
                    quickInfoContent.Add(
                        new ContentPresenter
                    {
                        Content         = content,
                        ContentTemplate = Template,
                    }
                        );
                    applicableToSpan = snapshot.CreateTrackingSpan(line.NameToken.Span.Span, SpanTrackingMode.EdgeInclusive);
                    return;
                }
            }
        /// <inheritdoc/>
        public Tuple <int, bool> GetLineNumber(IPeekSession session, ITrackingPoint point)
        {
            var diffModel          = (session.TextView as IWpfTextView)?.TextViewModel as IDifferenceTextViewModel;
            var leftBuffer         = false;
            ITextSnapshotLine line = null;

            if (diffModel != null)
            {
                if (diffModel.ViewType == DifferenceViewType.InlineView)
                {
                    // If we're displaying a diff in inline mode, then we need to map the point down
                    // to the left or right buffer.
                    var snapshotPoint = point.GetPoint(point.TextBuffer.CurrentSnapshot);
                    var mappedPoint   = session.TextView.BufferGraph.MapDownToFirstMatch(
                        snapshotPoint,
                        PointTrackingMode.Negative,
                        x => !(x is IProjectionSnapshot),
                        PositionAffinity.Successor);

                    if (mappedPoint != null)
                    {
                        leftBuffer = mappedPoint.Value.Snapshot == diffModel.Viewer.DifferenceBuffer.LeftBuffer.CurrentSnapshot;
                        line       = mappedPoint.Value.GetContainingLine();
                    }
                }
                else
                {
                    // If we're displaying a diff in any other mode than inline, then we're in the
                    // left buffer if the session's text view is the diff's left view.
                    leftBuffer = session.TextView == diffModel.Viewer.LeftView;
                }
            }

            if (line == null)
            {
                line = point.GetPoint(point.TextBuffer.CurrentSnapshot).GetContainingLine();
            }

            return(Tuple.Create(line.LineNumber, leftBuffer));
        }
        private ITrackingSpan FindApplicableSpan(ICompletionSession session)
        {
            // We eventually want to use an ITextStructureNavigator to expand the current point, but
            // first we have to teach it what out structure is.  For now, we just understand the Rtype
            // syntax directly.
            ////ITextStructureNavigator navigator = this.sourceProvider.NavigatorService.GetTextStructureNavigator(this.textBuffer);

            ITextSnapshot  snapshot     = session.TextView.TextSnapshot;
            ITrackingPoint triggerPoint = session.GetTriggerPoint(session.TextView.TextBuffer);

            // Look left and right until we're at a contextual break.
            SnapshotPoint initialPoint = triggerPoint.GetPoint(snapshot);
            SnapshotPoint leftPoint    = initialPoint;
            SnapshotPoint rightPoint   = initialPoint;

            ITextSnapshotLine line = leftPoint.GetContainingLine();

            // look left...
            if (leftPoint > line.Start)
            {
                leftPoint -= 1;
                while (leftPoint > line.Start && CompletionSource.IsTokenTermCharacter(leftPoint.GetChar()))
                {
                    leftPoint -= 1;
                }

                // If we bailed because of the character, advance back to the right.
                if (!CompletionSource.IsTokenTermCharacter(leftPoint.GetChar()))
                {
                    leftPoint += 1;
                }
            }

            // look right...
            // In theory, we might need to include spaces that are inside a quoted region, but we don't know if we've
            // just added the start-quote and might over-extend the selection.  It's safer to be conservative even if
            // it means leaving cruft in the buffer... it's easier for the user to delete the extra than to recover it if
            // we removed it.
            while (rightPoint < line.End && CompletionSource.IsTokenTermCharacter(rightPoint.GetChar()))
            {
                rightPoint += 1;
            }

            ITrackingSpan applicableSpan = snapshot.CreateTrackingSpan(
                leftPoint,
                rightPoint - leftPoint,
                SpanTrackingMode.EdgeInclusive);

            ////System.Diagnostics.Debug.WriteLine("**FindApplicableSpan: final span={0} ('{1}')", applicableSpan, applicableSpan.GetText(leftPoint.Snapshot));

            return(applicableSpan);
        }
Esempio n. 23
0
        public static Position Convert(this ITrackingPoint point, ITextSnapshot snapshot)
        {
            Contract.Requires(point != null);

            var snapshotPoint = point.GetPoint(snapshot);
            var line          = snapshotPoint.GetContainingLine();

            if (line == null)
            {
                return(default(Position));
            }
            int lineIndex = line.LineNumber;
            int charIndex = snapshotPoint.Position - line.Start.Position;

            return(new Position(lineIndex, charIndex));
        }
Esempio n. 24
0
        public static SnapshotPoint?GetTriggerPoint(ITextView textView, ITrackingPoint triggerPoint, ITextSnapshot textSnapshot)
        {
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }
            if (triggerPoint == null)
            {
                throw new ArgumentNullException(nameof(triggerPoint));
            }
            if (textSnapshot == null)
            {
                throw new ArgumentNullException(nameof(textSnapshot));
            }

            return(triggerPoint.GetPoint(textView.TextSnapshot));
        }
Esempio n. 25
0
        private void ProcessOutput(ITextSnapshot snapshot, ITrackingPoint startPoint, ITrackingPoint endPoint)
        {
            int    textStart  = startPoint.GetPosition(snapshot);
            int    textLength = endPoint.GetPoint(snapshot) - startPoint.GetPoint(snapshot);
            string text       = snapshot.GetText(textStart, textLength);

            BindingEntry[] entries = this.bindingParser.ParseOutput(text);

            if (entries.Length > 0)
            {
                this.JoinableTaskFactory.RunAsync(async delegate
                {
                    await this.JoinableTaskFactory.SwitchToMainThreadAsync();
                    this.viewModel.AddEntries(entries);
                }).FileAndForget(Constants.VsBindingPaneFeaturePrefix + nameof(this.ProcessOutput));
            }
        }
Esempio n. 26
0
        public override IEnumerable <INavigateToTarget> GoToSourceImpl(VSOBJGOTOSRCTYPE gotoSourceType, ITrackingPoint triggerPoint)
        {
            if (triggerPoint == null)
            {
                return(new INavigateToTarget[0]);
            }

            ITextSnapshot currentSnapshot = triggerPoint.TextBuffer.CurrentSnapshot;
            SnapshotPoint point           = triggerPoint.GetPoint(currentSnapshot);

            foreach (var span in this.ClassificationTagAggregator.GetTags(new SnapshotSpan(point, point)))
            {
                if (!span.Tag.ClassificationType.IsOfType(AntlrClassificationTypeNames.LexerRule) &&
                    !span.Tag.ClassificationType.IsOfType(AntlrClassificationTypeNames.ParserRule))
                {
                    continue;
                }

                NormalizedSnapshotSpanCollection spans = span.Span.GetSpans(currentSnapshot);
                if (spans.Count == 1)
                {
                    SnapshotSpan span2 = spans[0];
                    SnapshotSpan span3 = span.Span.GetSpans(span.Span.AnchorBuffer)[0];
                    if (span2.Length == span3.Length)
                    {
                        SnapshotSpan span4 = spans[0];
                        if (span4.Contains(point))
                        {
                            string ruleName = span2.GetText();
                            var    rules    = EditorNavigationSourceAggregator.GetNavigationTargets().ToArray();
                            var    rule     = rules.FirstOrDefault(x => string.Equals(x.Name, ruleName));
                            if (rule != null)
                            {
                                var snapshot     = rule.Seek.Snapshot;
                                var trackingSeek = snapshot.CreateTrackingSpan(rule.Seek.Span, SpanTrackingMode.EdgeExclusive);
                                var seek         = trackingSeek.GetSpan(TextView.TextBuffer.CurrentSnapshot);
                                return(new INavigateToTarget[] { new SnapshotSpanNavigateToTarget(TextView, seek) });
                            }
                        }
                    }
                }
            }

            return(new INavigateToTarget[0]);
        }
Esempio n. 27
0
        public override IEnumerable <INavigateToTarget> GoToSourceImpl(VSOBJGOTOSRCTYPE gotoSourceType, [NotNull] ITrackingPoint triggerPoint)
        {
            Requires.NotNull(triggerPoint, nameof(triggerPoint));

            if (triggerPoint == null)
            {
                return(new INavigateToTarget[0]);
            }

            ITextSnapshot currentSnapshot = triggerPoint.TextBuffer.CurrentSnapshot;
            SnapshotPoint point           = triggerPoint.GetPoint(currentSnapshot);

            foreach (var span in this.ClassificationTagAggregator.GetTags(new SnapshotSpan(point, point)))
            {
                if (!span.Tag.ClassificationType.IsOfType(AntlrClassificationTypeNames.LexerRule) &&
                    !span.Tag.ClassificationType.IsOfType(AntlrClassificationTypeNames.ParserRule))
                {
                    continue;
                }

                NormalizedSnapshotSpanCollection spans = span.Span.GetSpans(currentSnapshot);
                if (spans.Count == 1)
                {
                    SnapshotSpan span2 = spans[0];
                    SnapshotSpan span3 = span.Span.GetSpans(span.Span.AnchorBuffer)[0];
                    if (span2.Length == span3.Length)
                    {
                        SnapshotSpan span4 = spans[0];
                        if (span4.Contains(point))
                        {
                            string ruleName = span2.GetText();
                            var    rules    = BackgroundParser.RuleSpans;
                            KeyValuePair <ITrackingSpan, ITrackingPoint> value;
                            if (rules != null && rules.TryGetValue(ruleName, out value))
                            {
                                return new INavigateToTarget[] { new SnapshotSpanNavigateToTarget(TextView, new SnapshotSpan(value.Value.GetPoint(currentSnapshot), value.Value.GetPoint(currentSnapshot))) }
                            }
                            ;
                        }
                    }
                }
            }

            return(new INavigateToTarget[0]);
        }
Esempio n. 28
0
        private void AddTrackingPoint(CaretPosition caretPosition)
        {
            ITrackingPoint trackingPoint = _view.TextSnapshot.CreateTrackingPoint(caretPosition.BufferPosition.Position, PointTrackingMode.Positive);

            if (trackingPoint.GetPosition(_view.TextSnapshot) >= 0)
            {
                _trackPointList.Add(trackingPoint);
            }
            else
            {
                trackingPoint = _view.TextSnapshot.CreateTrackingPoint(0, PointTrackingMode.Positive);
                _trackPointList.Add(trackingPoint);
            }

            if (caretPosition.VirtualSpaces > 0)
            {
                _view.Caret.MoveTo(trackingPoint.GetPoint(_view.TextSnapshot));
            }
        }
Esempio n. 29
0
        private void ProcessOutput(ITextSnapshot snapshot, ITrackingPoint startPoint, ITrackingPoint endPoint)
        {
            int    textStart  = startPoint.GetPosition(snapshot);
            int    textLength = endPoint.GetPoint(snapshot) - startPoint.GetPoint(snapshot);
            string text       = snapshot.GetText(textStart, textLength);
            IReadOnlyList <ITableEntry> entries = this.outputParser.ParseOutput(text);

            if (entries.Count > 0)
            {
                this.package.JoinableTaskFactory.RunAsync(async delegate
                {
                    await this.package.JoinableTaskFactory.SwitchToMainThreadAsync();

                    if (this.viewModel.AddEntries(entries))
                    {
                        this.NotifyUserAboutNewEntries();
                    }
                }).FileAndForget(Constants.VsBindingPaneFeaturePrefix + nameof(this.ProcessOutput));
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Moves the data from one location to another in the buffer by deleting the selection contents and inserting toInsert in insertionPoint.
        /// </summary>
        /// <param name="data">Text to be inserted</param>
        /// <param name="position">Position at which the data is to be inserted</param>
        /// <param name="selectionSpans">A list of <see cref="ITrackingSpan"/> tracking the selection of the user before the drop operation. This span collection should be deleted from the buffer</param>
        /// <returns>True if data insertion and removal was successful, false otherwise.</returns>
        protected virtual bool MoveText(VirtualSnapshotPoint position, IList <ITrackingSpan> selectionSpans, string data)
        {
            ITextSnapshot textSnapshot = _cocoaTextView.TextSnapshot;

            // update position to the latest snapshot
            position = position.TranslateTo(textSnapshot);

            // keep track of where the data needs to be inserted
            ITrackingPoint insertionLocation = textSnapshot.CreateTrackingPoint(position.Position, PointTrackingMode.Negative);

            // delete the selection
            if (!this.DeleteSpans(selectionSpans))
            {
                return(false);
            }

            // move the caret to the data insertion point
            _cocoaTextView.Caret.MoveTo(new VirtualSnapshotPoint(insertionLocation.GetPoint(this.TextView.TextSnapshot), position.VirtualSpaces));

            // finally insert the data
            return(_editorOperations.InsertText(data));
        }
Esempio n. 31
0
        public void PreBackspace(out bool handledCommand)
        {
            handledCommand = false;

            SnapshotPoint?caretPos = CaretPosition;
            ITextSnapshot snapshot = SubjectBuffer.CurrentSnapshot;

            if (caretPos.HasValue && caretPos.Value.Position > 0 && (caretPos.Value.Position - 1) == _openingPoint.GetPoint(snapshot).Position &&
                !HasForwardTyping)
            {
                using (ITextUndoTransaction undo = CreateUndoTransaction())
                {
                    using (ITextEdit edit = SubjectBuffer.CreateEdit())
                    {
                        SnapshotSpan span = new SnapshotSpan(_openingPoint.GetPoint(snapshot), _closingPoint.GetPoint(snapshot));

                        edit.Delete(span);

                        if (edit.HasFailedChanges)
                        {
                            edit.Cancel();
                            undo.Cancel();
                            Debug.Fail("Unable to clear braces");
                            // just let this backspace proceed normally
                        }
                        else
                        {
                            // handle the command so the backspace does
                            // not go through since we've already cleared the braces
                            handledCommand = true;
                            edit.Apply();
                            undo.Complete();
                            EndSession();
                        }
                    }
                }
            }
        }
Esempio n. 32
0
        /// <summary>
        /// Draw a caret in its position
        /// </summary>
        /// <param name="curTrackPoint"></param>
        /// <param name="brush"></param>
        private void DrawSingleSyncPoint(ITrackingPoint curTrackPoint, SolidColorBrush brush)
        {
            SnapshotSpan span;
            SnapshotPoint tempSnapPoint = curTrackPoint.GetPoint(m_textView.TextSnapshot);
            if (tempSnapPoint.Position != m_textView.TextSnapshot.Length)
            {
                //m_textView.TextSnapshot.TextBuffer.Insert(tempSnapPoint.Position, " ");
                //tempSnapPoint = tempSnapPoint.Subtract(1);
                span = new SnapshotSpan(tempSnapPoint, 1);
                var g = m_textView.TextViewLines.GetLineMarkerGeometry(span);
                GeometryDrawing drawing = new GeometryDrawing(brush, null, g);
                if (drawing.Bounds.IsEmpty)
                    return;

                System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle()
                {
                    Fill = brush,
                    Width = drawing.Bounds.Width / 4,
                    Height = drawing.Bounds.Height
                };
                Canvas.SetLeft(r, g.Bounds.Left);
                Canvas.SetTop(r, g.Bounds.Top);
                m_adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "MultiEditLayer", r, null);
            }

        }
        private void DrawSingleSyncPoint(ITrackingPoint trackPoint)
        {
            if (trackPoint.GetPosition(m_textView.TextSnapshot) >= m_textView.TextSnapshot.Length)
                return;

            SnapshotSpan span = new SnapshotSpan(trackPoint.GetPoint(m_textView.TextSnapshot), 1);
            var brush = Brushes.DarkGray;
            var geom = m_textView.TextViewLines.GetMarkerGeometry(span);
            GeometryDrawing drawing = new GeometryDrawing(brush, null, geom);

            if (drawing.Bounds.IsEmpty)
                return;

            Rectangle rect = new Rectangle()
            {
                Fill = brush,
                Width = 1,
                Height = drawing.Bounds.Height - 1,
                Margin = new Thickness(),
            };

            Canvas.SetLeft(rect, geom.Bounds.Left);
            Canvas.SetTop(rect, geom.Bounds.Top);
            m_adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "MultiEditLayer", rect, null);
        }
Esempio n. 34
0
        private void DrawSingleSyncPoint(ITrackingPoint trackPoint)
        {
            var position = trackPoint.GetPosition(m_textView.TextSnapshot);
            if (position > m_textView.TextSnapshot.Length)
                return;

            var point = trackPoint.GetPoint(m_textView.TextSnapshot);
            if (position == m_textView.TextSnapshot.Length)
                point -= 1;

            var span = new SnapshotSpan(point, 1);

            var brush = Brushes.DarkGray;
            var geom = m_textView.TextViewLines.GetLineMarkerGeometry(span);
            var drawing = new GeometryDrawing(brush, null, geom);

            if (drawing.Bounds.IsEmpty)
                return;

            Rectangle rect = new Rectangle()
            {
                Fill = brush,
                Width = drawing.Bounds.Width / 6,
                Height = drawing.Bounds.Height - 4,
                Margin = new System.Windows.Thickness(0, 2, 0, 0)
            };

            Canvas.SetLeft(rect, position == m_textView.TextSnapshot.Length ? geom.Bounds.Right : geom.Bounds.Left);
            Canvas.SetTop(rect, geom.Bounds.Top);

            m_adornmentLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, "MultiEditLayer", rect, null);
        }
        public override IEnumerable<INavigateToTarget> GoToSourceImpl(VSOBJGOTOSRCTYPE gotoSourceType, ITrackingPoint triggerPoint)
        {
            if (triggerPoint == null)
                return new INavigateToTarget[0];

            ITextSnapshot currentSnapshot = triggerPoint.TextBuffer.CurrentSnapshot;
            SnapshotPoint point = triggerPoint.GetPoint(currentSnapshot);

            foreach (var span in this.ClassificationTagAggregator.GetTags(new SnapshotSpan(point, point)))
            {
                if (!span.Tag.ClassificationType.IsOfType(AntlrClassificationTypeNames.LexerRule)
                    && !span.Tag.ClassificationType.IsOfType(AntlrClassificationTypeNames.ParserRule))
                {
                    continue;
                }

                NormalizedSnapshotSpanCollection spans = span.Span.GetSpans(currentSnapshot);
                if (spans.Count == 1)
                {
                    SnapshotSpan span2 = spans[0];
                    SnapshotSpan span3 = span.Span.GetSpans(span.Span.AnchorBuffer)[0];
                    if (span2.Length == span3.Length)
                    {
                        SnapshotSpan span4 = spans[0];
                        if (span4.Contains(point))
                        {
                            string ruleName = span2.GetText();
                            var rules = BackgroundParser.RuleSpans;
                            KeyValuePair<ITrackingSpan, ITrackingPoint> value;
                            if (rules != null && rules.TryGetValue(ruleName, out value))
                                return new INavigateToTarget[] { new SnapshotSpanNavigateToTarget(TextView, new SnapshotSpan(value.Value.GetPoint(currentSnapshot), value.Value.GetPoint(currentSnapshot))) };
                        }
                    }
                }
            }

            return new INavigateToTarget[0];
        }