Beispiel #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 <CustomTag> > GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
        {
            if (snapshotRanges != null)
            {
                // Loop through the snapshot ranges
                foreach (TextSnapshotRange snapshotRange in snapshotRanges)
                {
                    // Get the text of the snapshot range
                    string text = snapshotRange.Text;

                    // Look for a regex pattern match
                    MatchCollection matches = Regex.Matches(text, pattern, RegexOptions.IgnoreCase);
                    if (matches.Count > 0)
                    {
                        // Loop through the matches
                        foreach (Match match in matches)
                        {
                            // Create a tag
                            CustomTag tag = new CustomTag();

                            // Yield the tag
                            yield return(new TagSnapshotRange <CustomTag>(
                                             TextSnapshotRange.FromSpan(snapshotRange.Snapshot, snapshotRange.StartOffset + match.Index, match.Length), tag));
                        }
                    }
                }
            }
        }
Beispiel #2
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 <ColorPreviewTag> > GetTags(NormalizedTextSnapshotRangeCollection snapshotRanges, object parameter)
        {
            if (snapshotRanges != null)
            {
                // Loop through the snapshot ranges
                foreach (TextSnapshotRange snapshotRange in snapshotRanges)
                {
                    // Get the text of the snapshot range
                    string text = snapshotRange.Text;

                    // Look for a regex pattern match
                    MatchCollection matches = Regex.Matches(text, this.Pattern, RegexOptions.IgnoreCase);
                    if (matches.Count > 0)
                    {
                        // Loop through the matches
                        foreach (Match match in matches)
                        {
                            // Create a tag
                            ColorPreviewTag tag = new ColorPreviewTag();
                            tag.Color = UIColor.FromWebColor(match.Value).ToColor();

                            // Ensure full alpha
                            if (tag.Color.A < 255)
                            {
                                tag.Color = Color.FromArgb(255, tag.Color.R, tag.Color.G, tag.Color.B);
                            }

                            // Yield the tag
                            yield return(new TagSnapshotRange <ColorPreviewTag>(
                                             TextSnapshotRange.FromSpan(snapshotRange.Snapshot, snapshotRange.StartOffset + match.Index, match.Length), tag));
                        }
                    }
                }
            }
        }