/// <summary>
        /// Creates an ElasticTabstopsFormatters for
        /// the provided configuration.
        /// </summary>
        public TextParagraphProperties Create(IFormattedLineSource formattedLineSource, TextFormattingRunProperties textProperties,
                                              IMappingSpan line, IMappingPoint lineStart, int lineSegment)
        {
            if (!AlwaysAlignedConfigurationService.Instance.GetConfiguration().Enabled)
            {
                return(new TextFormattingParagraphProperties(textProperties, formattedLineSource.ColumnWidth * formattedLineSource.TabSize));
            }

            IWpfTextView textView = _textBufferToViewMapService.GetViewByFormattedLineSource(formattedLineSource);

            //View is not initialized yet
            if (textView == null)
            {
                return(new TextFormattingParagraphProperties(textProperties, formattedLineSource.ColumnWidth * formattedLineSource.TabSize));
            }
            var manager = ElasticTabstopsSizeManager.Get(textView);

            ITextSnapshot textSnapshot = formattedLineSource.SourceTextSnapshot;
            ITextBuffer   textBuffer   = textSnapshot.TextBuffer;

            var normalizedspancoll        = line.GetSpans(textBuffer);
            ITextSnapshotLine currentLine = textSnapshot.GetLineFromPosition(normalizedspancoll.First().Start.Position);

            //Get tab offset calculated by ElasticTabstopsSizeManager
            double[] tabOffsets = manager.GetTabOffsets(currentLine);

            return(new ElasticTabstopsFormatter(textProperties, formattedLineSource, tabOffsets));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of a <see cref="CaretPosition"/>.
        /// </summary>
        /// <param name="bufferPosition">The index of the caret. This corresponds to a gap between two characters in the underlying <see cref="ITextBuffer"/>.</param>
        /// <param name="mappingPoint">A mapping point for the caret that can be used to find its position in any buffer.</param>
        /// <param name="caretAffinity">The <see cref="PositionAffinity"/> of the caret. The caret can have an affinity with
        /// the preceding edge of the gap or the following edge of the gap.</param>
        public CaretPosition(VirtualSnapshotPoint bufferPosition, IMappingPoint mappingPoint, PositionAffinity caretAffinity)
        {
            if (mappingPoint == null)
            {
                throw new ArgumentNullException("mappingPoint");
            }

            _bufferPosition = bufferPosition;
            _mappingPoint   = mappingPoint;
            _affinity       = caretAffinity;
        }
 /// <summary>
 ///   Creates a <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> for the provided configuration.
 /// </summary>
 /// <param name = "formattedLineSource">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.IFormattedLineSource" /> that's performing the formatting of the line. You can access useful properties about the ongoing formatting operation from this object.</param>
 /// <param name = "textProperties">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties" /> of the line for which <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> are to be provided. This paramter can be used to obtain formatting information about the textual contents of the line.</param>
 /// <param name = "line">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingSpan" /> corresponding to the line that's being formatted/rendered.</param>
 /// <param name = "lineStart">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingPoint" /> corresponding to the beginning of the line segment that's being formatted. This paramter is relevant for word-wrap scenarios where a single <see cref = "T:Microsoft.VisualStudio.Text.ITextSnapshotLine" /> results in multiple formatted/rendered lines on the view.</param>
 /// <param name = "lineSegment">The segment number of the line segment that's been currently formatted. This is a zero-based index and is applicable to word-wrapped lines. If a line is word-wrapped into 4 segments, you will receive 4 calls for the line with lineSegments of 0, 1, 2, and 3.</param>
 /// <returns>
 ///   A <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> to be used when the line is being formatted.
 /// </returns>
 /// <remarks>
 ///   Please note that you can return a <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingParagraphProperties" /> which has a convenient set of basic properties defined.
 /// </remarks>
 public TextParagraphProperties Create(IFormattedLineSource formattedLineSource,
                                       TextFormattingRunProperties textProperties,
                                       IMappingSpan line,
                                       IMappingPoint lineStart,
                                       int lineSegment)
 {
     if (_TextParagraphProperties == null)
     {
         _TextParagraphProperties = new PowerShellTextFormattingParagraphProperties(textProperties,
                                                                                    formattedLineSource,
                                                                                    ServiceProvider);
     }
     return(TextParagraphProperties);
 }
 /// <summary>
 ///   Creates a <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> for the provided configuration.
 /// </summary>
 /// <param name = "formattedLineSource">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.IFormattedLineSource" /> that's performing the formatting of the line. You can access useful properties about the ongoing formatting operation from this object.</param>
 /// <param name = "textProperties">The <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties" /> of the line for which <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> are to be provided. This paramter can be used to obtain formatting information about the textual contents of the line.</param>
 /// <param name = "line">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingSpan" /> corresponding to the line that's being formatted/rendered.</param>
 /// <param name = "lineStart">The <see cref = "T:Microsoft.VisualStudio.Text.IMappingPoint" /> corresponding to the beginning of the line segment that's being formatted. This paramter is relevant for word-wrap scenarios where a single <see cref = "T:Microsoft.VisualStudio.Text.ITextSnapshotLine" /> results in multiple formatted/rendered lines on the view.</param>
 /// <param name = "lineSegment">The segment number of the line segment that's been currently formatted. This is a zero-based index and is applicable to word-wrapped lines. If a line is word-wrapped into 4 segments, you will receive 4 calls for the line with lineSegments of 0, 1, 2, and 3.</param>
 /// <returns>
 ///   A <see cref = "T:System.Windows.Media.TextFormatting.TextParagraphProperties" /> to be used when the line is being formatted.
 /// </returns>
 /// <remarks>
 ///   Please note that you can return a <see cref = "T:Microsoft.VisualStudio.Text.Formatting.TextFormattingParagraphProperties" /> which has a convenient set of basic properties defined.
 /// </remarks>
 public TextParagraphProperties Create( IFormattedLineSource formattedLineSource,
     TextFormattingRunProperties textProperties,
     IMappingSpan line,
     IMappingPoint lineStart,
     int lineSegment)
 {
     if (_TextParagraphProperties == null)
     {
         _TextParagraphProperties = new PowerShellTextFormattingParagraphProperties( textProperties,
                                                                                     formattedLineSource,
                                                                                     ServiceProvider );
     }
     return TextParagraphProperties;
 }
Esempio n. 5
0
        void ImmediateCaretPositionChanged(object sender, CaretLocationEventArgs args)
        {
            // MD doesn't fire textEditor.CaretPositionChanged until after the command has gone completely through the command chain.
            //   Too much VS stuff depends on it getting updated earlier, so we'll use this event which fires earlier.
            int position             = _textEditor.CaretOffset;
            VirtualSnapshotPoint vsp = new VirtualSnapshotPoint(_textView.TextSnapshot, position);

            _insertionPoint = vsp;
            if (args.CaretChangeReason == CaretChangeReason.Movement)
            {
                SnapshotPoint snapshotPoint             = new SnapshotPoint(_textView.TextSnapshot, position);
                IMappingPoint mappingPoint              = _textView.BufferGraph.CreateMappingPoint(snapshotPoint, PointTrackingMode.Positive);
                CaretPosition newCaretPosition          = new CaretPosition(vsp, mappingPoint, _caretAffinity);
                CaretPositionChangedEventArgs eventArgs = new CaretPositionChangedEventArgs(_textView, Position, newCaretPosition);

                PositionChanged?.Invoke(this, eventArgs);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of a <see cref="MouseHoverEventArgs"/>.
        /// </summary>
        /// <param name="view">The view in which the hover event is being generated.</param>
        /// <param name="position">The position of the character under the mouse in the snapshot span of the view.</param>
        /// <param name="textPosition">The position mapped to the buffer graph of the character under the mouse.</param>
        /// <exception cref="ArgumentNullException"><paramref name="view"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="position"/> is negative or greater than the length of the view's buffer.</exception>
        public MouseHoverEventArgs(ITextView view, int position, IMappingPoint textPosition)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
#pragma warning suppress 56506                                           // ToDo: Add a comment on why it is not necessary to check view.TextSnapshot
            if ((position < 0) || (position > view.TextSnapshot.Length)) // Allow positions at the end of the file
            {
                throw new ArgumentOutOfRangeException("position");
            }
            if (textPosition == null)
            {
                throw new ArgumentNullException("textPosition");
            }
            // we could be very paranoid and check:
            //if (textPosition.AnchorBuffer != view.TextBuffer)
            //    throw new ArgumentException();

            _view         = view;
            _position     = position;
            _textPosition = textPosition;
        }
        /// <summary>
        /// If the text position is within a colour then show that could on the screen
        /// </summary>
        /// <param name="position"></param>
        /// <param name="textPosition"></param>
        /// <param name="textView"></param>
        private void ShowColourSwatch(int position, IMappingPoint textPosition, ITextView textView)
        {
            _layer.RemoveAllAdornments();
            SnapshotPoint? snapPoint = textPosition.GetPoint(textPosition.AnchorBuffer, PositionAffinity.Predecessor);
            if (snapPoint.HasValue)
            {
                SnapshotSpan charSpan = textView.GetTextElementSpan(snapPoint.Value);
                var colourPos = _colourPositions.Find(cp => (cp.Item1 <= charSpan.Start) && (cp.Item2 >= charSpan.Start));
                if(colourPos != null)
                {

                    Image image = CreateSwatchImage(colourPos, charSpan);

                    _layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, charSpan, null, image, null);
                    Thread t = new Thread(p =>
                    {
                        Thread.Sleep(3500);
                        lock (lockObject)
                        {
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                _layer.RemoveAdornmentsByVisualSpan(charSpan);
                            }), new object[]{});
                        }
                    });
                    t.Start();
                }
            }
        }
Esempio n. 8
0
 SnapshotPoint?Map(IMappingPoint p, ITextSnapshot textSnapshot)
 {
     return(p.GetPoint(textSnapshot.TextBuffer, PositionAffinity.Predecessor));
 }
Esempio n. 9
0
 public ErrorMark(IMappingPoint position, object content, Color color)
 {
     _position = position;
     _content  = content;
     _color    = color;
 }
Esempio n. 10
0
        private void HandleContentTypeTagsChanged()
        {
            ITextSnapshot snapshot     = DiskBuffer.CurrentSnapshot;
            ITextSnapshot htmlSnapshot = _htmlBuffer.CurrentSnapshot;
            ITextSnapshot phpSnapshot  = TemplateBuffer.CurrentSnapshot;

            SnapshotSpan completeSnapshot = new SnapshotSpan(snapshot, 0, snapshot.Length);

            IMappingTagSpan <ContentTypeTag>[] tags = _contentTypeTagger.GetTags(completeSnapshot).ToArray();

            IMappingPoint[] trackingPoints = new IMappingPoint[tags.Length];
            for (int i = 0; i < tags.Length; i++)
            {
                IMappingTagSpan <ContentTypeTag> tag = tags[i];
                switch (tag.Tag.RegionType)
                {
                case RegionType.Begin:
                    trackingPoints[i] = tag.Span.Start;
                    break;

                case RegionType.End:
                    trackingPoints[i] = tag.Span.End;
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            List <ITrackingSpan> projectionSpans = new List <ITrackingSpan>();
            List <SpanInfo>      spans           = new List <SpanInfo>();

            for (int i = 0; i < tags.Length; i++)
            {
                IMappingTagSpan <ContentTypeTag> tag = tags[i];

                Span sourceSpan;
                if (i == 0)
                {
                    sourceSpan = new Span(0, trackingPoints[0].GetPoint(snapshot, PositionAffinity.Successor) ?? 0);
                }
                else
                {
                    SnapshotPoint?startPoint = trackingPoints[i - 1].GetPoint(snapshot, PositionAffinity.Successor);
                    SnapshotPoint?endPoint   = trackingPoints[i].GetPoint(snapshot, PositionAffinity.Successor);
                    if (!startPoint.HasValue || !endPoint.HasValue)
                    {
                        throw new InvalidOperationException();
                    }

                    sourceSpan = Span.FromBounds(startPoint.Value.Position, endPoint.Value.Position);
                }

                switch (tag.Tag.RegionType)
                {
                case RegionType.Begin:
                {
                    // handle the Text region that ended where this tag started
                    ITrackingSpan projectionSpan = htmlSnapshot.Version.CreateCustomTrackingSpan(
                        sourceSpan,
                        TrackingFidelityMode.Forward,
                        new LanguageSpanCustomState(sourceSpan),
                        TrackToVersion);
                    ITrackingSpan diskBufferSpan = snapshot.Version.CreateCustomTrackingSpan(
                        sourceSpan,
                        TrackingFidelityMode.Forward,
                        new LanguageSpanCustomState(sourceSpan),
                        TrackToVersion);

                    projectionSpans.Add(projectionSpan);
                    spans.Add(new SpanInfo(diskBufferSpan, TemplateTokenKind.Text));
                    break;
                }

                case RegionType.End:
                {
                    // handle the code region that ended where this tag ended
                    ITrackingSpan projectionSpan = new CustomTrackingSpan(phpSnapshot.CreateTrackingSpan(sourceSpan, SpanTrackingMode.EdgeExclusive));
                    ITrackingSpan diskBufferSpan = new CustomTrackingSpan(snapshot.CreateTrackingSpan(sourceSpan, SpanTrackingMode.EdgeExclusive));

                    projectionSpans.Add(projectionSpan);
                    spans.Add(new SpanInfo(diskBufferSpan, TemplateTokenKind.Block));
                    break;
                }

                default:
                    throw new NotSupportedException();
                }
            }

            if (true)
            {
                int startPosition = 0;
                if (tags.Length > 0)
                {
                    SnapshotPoint?startPoint = trackingPoints.Last().GetPoint(snapshot, PositionAffinity.Successor);
                    if (!startPoint.HasValue)
                    {
                        throw new InvalidOperationException();
                    }

                    startPosition = startPoint.Value.Position;
                }

                Span sourceSpan = Span.FromBounds(startPosition, snapshot.Length);

                RegionType finalRegionType = tags.Length > 0 ? tags.Last().Tag.RegionType : RegionType.End;
                switch (finalRegionType)
                {
                case RegionType.Begin:
                {
                    // handle the code region that ended at the end of the document
                    ITrackingSpan projectionSpan = new CustomTrackingSpan(phpSnapshot.CreateTrackingSpan(sourceSpan, SpanTrackingMode.EdgePositive));
                    ITrackingSpan diskBufferSpan = new CustomTrackingSpan(snapshot.CreateTrackingSpan(sourceSpan, SpanTrackingMode.EdgePositive));

                    projectionSpans.Add(projectionSpan);
                    spans.Add(new SpanInfo(diskBufferSpan, TemplateTokenKind.Block));
                    break;
                }

                case RegionType.End:
                {
                    // handle the Text region that ended at the end of the document
                    ITrackingSpan projectionSpan = htmlSnapshot.Version.CreateCustomTrackingSpan(
                        sourceSpan,
                        TrackingFidelityMode.Forward,
                        new LanguageSpanCustomState(sourceSpan),
                        TrackToVersion);
                    ITrackingSpan diskBufferSpan = snapshot.Version.CreateCustomTrackingSpan(
                        sourceSpan,
                        TrackingFidelityMode.Forward,
                        new LanguageSpanCustomState(sourceSpan),
                        TrackToVersion);

                    projectionSpans.Add(projectionSpan);
                    spans.Add(new SpanInfo(diskBufferSpan, TemplateTokenKind.Text));
                    break;
                }

                default:
                    throw new NotSupportedException();
                }
            }

            int startSpan    = 0;
            int oldSpanCount = _spans.Count;

            _spans.RemoveRange(startSpan, oldSpanCount - startSpan);
            _spans.AddRange(spans);

            _projBuffer.ReplaceSpans(startSpan, oldSpanCount - startSpan, projectionSpans.ToArray(), _editOptions, null);

            ProjectionClassifier classifier;

            if (spans.Count > 0 &&
                _projBuffer.Properties.TryGetProperty <ProjectionClassifier>(typeof(ProjectionClassifier), out classifier))
            {
                classifier.RaiseClassificationChanged(
                    spans[0].DiskBufferSpan.GetStartPoint(_diskBuffer.CurrentSnapshot),
                    spans[spans.Count - 1].DiskBufferSpan.GetEndPoint(_diskBuffer.CurrentSnapshot)
                    );
            }
        }
Esempio n. 11
0
 private Mark(IMappingTagSpan <IVsVisibleTextMarkerTag> tag)
 {
     _tag      = tag.Tag;
     _position = tag.Span.Start;
 }