Skip to content

Commit

Permalink
Merge pull request #365 from X-Sharp/master
Browse files Browse the repository at this point in the history
Add virtual property TextMarkerTagType for SameWordHighLighterBase th…
  • Loading branch information
madskristensen authored Jul 28, 2022
2 parents f1c02be + 6e37c92 commit f5d1789
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class SameWordHighlighterBase : IViewTaggerProvider

[Import] internal ITextStructureNavigatorSelectorService? _textStructureNavigatorSelector = null;

/// <summary>
/// Return the tag name for the HighlightWord tags. Defaults to "MarkerFormatDefinition/HighlightWordFormatDefinition".
/// Can be overwritten in a subclass to change the format of the tags.
/// </summary>
public virtual string TextMarkerTagType => "MarkerFormatDefinition/HighlightWordFormatDefinition";
/// <summary>
/// The Options that are used to find the matching words. The default implementation returns
/// FindOptions.WholeWord | FindOptions.MatchCase
Expand Down Expand Up @@ -50,7 +55,7 @@ public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where

internal class HighlightWordTag : TextMarkerTag
{
public HighlightWordTag() : base("MarkerFormatDefinition/HighlightWordFormatDefinition") { }
public HighlightWordTag(string tagName) : base(tagName) { }
}

internal class SameWordHighlighterTagger : ITagger<HighlightWordTag>, IDisposable
Expand Down Expand Up @@ -190,13 +195,13 @@ public IEnumerable<ITagSpan<HighlightWordTag>> GetTags(NormalizedSnapshotSpanCol
// the duplication here is expected.
if (spans.OverlapsWith(new NormalizedSnapshotSpanCollection(currentWord)))
{
yield return new TagSpan<HighlightWordTag>(currentWord, new HighlightWordTag());
yield return new TagSpan<HighlightWordTag>(currentWord, new HighlightWordTag(_tagger.TextMarkerTagType));
}

// Second, yield all the other words in the file
foreach (SnapshotSpan span in NormalizedSnapshotSpanCollection.Overlap(spans, wordSpans))
{
yield return new TagSpan<HighlightWordTag>(span, new HighlightWordTag());
yield return new TagSpan<HighlightWordTag>(span, new HighlightWordTag(_tagger.TextMarkerTagType));
}
}

Expand Down

0 comments on commit f5d1789

Please sign in to comment.