Пример #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns the tag ranges that intersect with the specified normalized snapshot ranges.
        /// </summary>
        /// <param name="snapshotRanges">The collection of normalized snapshot ranges.</param>
        /// <param name="parameter">An optional parameter that provides contextual information about the tag request.</param>
        /// <returns>The tag ranges that intersect with the specified normalized snapshot ranges.</returns>
        public override IEnumerable <TagSnapshotRange <IClassificationTag> > GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
        {
            // Loop through the requested snapshot ranges...
            foreach (TextSnapshotRange snapshotRange in snapshotRanges)
            {
                // If the snapshot range is not zero-length...
                if (!snapshotRange.IsZeroLength)
                {
                    // Get a snapshot reader
                    ITextSnapshotReader reader = snapshotRange.Snapshot.GetReader(snapshotRange.StartOffset);

                    // If not already at the start of a line, back up to the start
                    if (!reader.IsAtSnapshotLineStart)
                    {
                        reader.GoToCurrentSnapshotLineStart();
                    }

                    // Read through the snapshot until the end of the target range is reached
                    while ((!reader.IsAtSnapshotEnd) && (reader.Offset < snapshotRange.EndOffset))
                    {
                        // Save the start of the line offset
                        int lineStartOffset = reader.Offset;

                        // Get the line start text (we need at most 6 chars for this sample)
                        string lineStartText = reader.PeekText(6);

                        // Go to the end of the line
                        reader.GoToCurrentSnapshotLineEnd();

                        // Add a range for the line if it starts with one of the defined strings...
                        //   The StyleRegistryClassificationTag is a special ClassificationTag that allows you to indicate
                        //   an alternate IHighlightingStyleRegistry to use for syntax highlighting... if using the
                        //   normal AmbientHighlightingStyleRegistry, you'd just use a regular ClassificationTag instead
                        if (lineStartText.StartsWith("---"))
                        {
                            // Apply green to lines that start with "---"
                            yield return(new TagSnapshotRange <IClassificationTag>(
                                             new TextSnapshotRange(snapshotRange.Snapshot, new TextRange(lineStartOffset, reader.Offset)),
                                             new StyleRegistryClassificationTag(commentCT, styleRegistry)
                                             ));
                        }
                        else if (lineStartText.StartsWith("Error:"))
                        {
                            // Apply maroon to lines that start with "Error:"
                            yield return(new TagSnapshotRange <IClassificationTag>(
                                             new TextSnapshotRange(snapshotRange.Snapshot, new TextRange(lineStartOffset, reader.Offset)),
                                             new StyleRegistryClassificationTag(errorCT, styleRegistry)
                                             ));
                        }

                        // Consume the newline
                        reader.GoToNextSnapshotLineStart();
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Occurs when the link is clicked.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param>
 private void OnGoToCurrentLineStartHyperlinkClick(object sender, RoutedEventArgs e)
 {
     reader.Offset = editor.ActiveView.Selection.EndOffset;
     reader.GoToCurrentSnapshotLineStart();
     this.AppendMessageAndUpdateUI("Current line start", false);
 }