forked from akaStiX/ProgressiveScrollVS2017
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HighlightWordTaggerProvider.cs
63 lines (52 loc) · 2.04 KB
/
HighlightWordTaggerProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
namespace ProgressiveScroll
{
[Export(typeof (IViewTaggerProvider))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
[TagType(typeof (ClassificationTag))]
internal class HighlightWordTaggerProvider : IViewTaggerProvider
{
[Import]
internal ITextSearchService TextSearchService { get; set; }
[Import]
internal ITextStructureNavigatorSelectorService TextStructureNavigatorSelector { get; set; }
[Import]
public IClassificationTypeRegistryService Registry { get; set; }
// HACK: Keeps track of all the HighlightWordTaggers
private static readonly Dictionary<ITextView, HighlightWordTagger> _taggers =
new Dictionary<ITextView, HighlightWordTagger>();
public static Dictionary<ITextView, HighlightWordTagger> Taggers
{
get { return _taggers; }
}
public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
{
// Provide highlighting only on the top buffer
// HTML files for instance will fail here
if (textView.TextBuffer != buffer)
return null;
// This checks for diff/merge type views
if (textView.Roles.ContainsAny(ProgressiveScrollFactory.RejectedRoles))
{
return null;
}
ITextStructureNavigator textStructureNavigator =
TextStructureNavigatorSelector.GetTextStructureNavigator(buffer);
IClassificationType classificationType = Registry.GetClassificationType(ClassificationNames.Highlights);
var tagger = new HighlightWordTagger(textView as IWpfTextView, buffer, TextSearchService, textStructureNavigator, classificationType);
Taggers[textView] = tagger;
return tagger as ITagger<T>;
}
}
}