diff --git a/Codist/Constants.cs b/Codist/Constants.cs index de1719a0..97d53937 100644 --- a/Codist/Constants.cs +++ b/Codist/Constants.cs @@ -65,6 +65,7 @@ public static class EditorFormatKeys public const string CodeKeyword = "Keyword"; public const string CodeComment = "Comment"; + public const string CodeText = "text"; public const string CSharpAbstractionKeyword = "C#: Abstraction keyword"; public const string CSharpBranchingKeyword = "C#: Branching keyword"; diff --git a/Codist/NaviBar/MarkdownBar.cs b/Codist/NaviBar/MarkdownBar.cs index 7999fd97..39a2003a 100644 --- a/Codist/NaviBar/MarkdownBar.cs +++ b/Codist/NaviBar/MarkdownBar.cs @@ -19,13 +19,19 @@ namespace Codist.NaviBar public sealed class MarkdownBar : NaviBar { const string DefaultActiveTitle = "Headings"; - static readonly IClassificationType - _H1 = ServicesHelper.Instance.ClassificationTypeRegistry.GetClassificationType(Constants.MarkdownHeading1), - _H2 = ServicesHelper.Instance.ClassificationTypeRegistry.GetClassificationType(Constants.MarkdownHeading2), - _H3 = ServicesHelper.Instance.ClassificationTypeRegistry.GetClassificationType(Constants.MarkdownHeading3), - _H4 = ServicesHelper.Instance.ClassificationTypeRegistry.GetClassificationType(Constants.MarkdownHeading4), - _H5 = ServicesHelper.Instance.ClassificationTypeRegistry.GetClassificationType(Constants.MarkdownHeading5), - _H6 = ServicesHelper.Instance.ClassificationTypeRegistry.GetClassificationType(Constants.MarkdownHeading6); + static readonly Microsoft.VisualStudio.Text.Tagging.ClassificationTag + _H1 = MarkdownTaggerProvider.HeaderClassificationTypes[1], + _H2 = MarkdownTaggerProvider.HeaderClassificationTypes[2], + _H3 = MarkdownTaggerProvider.HeaderClassificationTypes[3], + _H4 = MarkdownTaggerProvider.HeaderClassificationTypes[4], + _H5 = MarkdownTaggerProvider.HeaderClassificationTypes[5], + _H6 = MarkdownTaggerProvider.HeaderClassificationTypes[6], + _DummyTag1 = MarkdownTaggerProvider.DummyHeaderTags[1], + _DummyTag2 = MarkdownTaggerProvider.DummyHeaderTags[2], + _DummyTag3 = MarkdownTaggerProvider.DummyHeaderTags[3], + _DummyTag4 = MarkdownTaggerProvider.DummyHeaderTags[4], + _DummyTag5 = MarkdownTaggerProvider.DummyHeaderTags[5], + _DummyTag6 = MarkdownTaggerProvider.DummyHeaderTags[6]; readonly ITextSearchService2 _TextSearch; readonly TaggerResult _Tags; readonly ThemedToolBarText _ActiveTitleLabel; @@ -273,27 +279,27 @@ static Thickness public LocationItem(TaggedContentSpan span) { _Span = span; Content = new ThemedMenuText(span.ContentText); - var t = span.Tag.ClassificationType; - if (t == _H1) { + var t = span.Tag; + if (t == _H1 || t == _DummyTag1) { Content.FontWeight = FontWeights.Bold; _ImageId = IconIds.Heading1; } - else if (t == _H2) { + else if (t == _H2 || t == _DummyTag2) { _ImageId = IconIds.Heading2; } - else if (t == _H3) { + else if (t == _H3 || t == _DummyTag3) { _ImageId = IconIds.Heading3; Content.Padding = _H3Padding; } - else if (t == _H4) { + else if (t == _H4 || t == _DummyTag4) { _ImageId = IconIds.Heading4; Content.Padding = _H4Padding; } - else if (t == _H5) { + else if (t == _H5 || t == _DummyTag5) { _ImageId = IconIds.Heading5; Content.Padding = _H5Padding; } - else if (t == _H6) { + else if (t == _H6 || t == _DummyTag6) { _ImageId = IconIds.None; Content.Padding = _H6Padding; } diff --git a/Codist/Taggers/MarkdownTagger.cs b/Codist/Taggers/MarkdownTagger.cs index 7ce92cb1..994add17 100644 --- a/Codist/Taggers/MarkdownTagger.cs +++ b/Codist/Taggers/MarkdownTagger.cs @@ -17,34 +17,45 @@ namespace Codist.Taggers [TagType(typeof(IClassificationTag))] sealed class MarkdownTaggerProvider : IViewTaggerProvider { - static readonly ClassificationTag[] _HeaderClassificationTypes = new ClassificationTag[7]; + internal static readonly ClassificationTag[] HeaderClassificationTypes = new ClassificationTag[7]; + internal static readonly ClassificationTag[] DummyHeaderTags = new ClassificationTag[7]; // used when syntax highlight is disabled public ITagger CreateTagger(ITextView textView, ITextBuffer buffer) where T : ITag { - if (Config.Instance.Features.MatchFlags(Features.SyntaxHighlight) == false) { + // the results produced by the tagger are also reused by the NaviBar + if (Config.Instance.Features.HasAnyFlag(Features.SyntaxHighlight | Features.NaviBar) == false) { return null; } if (textView.TextBuffer.LikeContentType(Constants.CodeTypes.Markdown) == false) { return null; } - if (_HeaderClassificationTypes[1] == null) { + if (HeaderClassificationTypes[1] == null) { InitHeaderClassificationTypes(); } - return textView.Properties.GetOrCreateSingletonProperty(() => new MarkdownTagger(textView)) as ITagger; + return textView.Properties.GetOrCreateSingletonProperty(() => new MarkdownTagger(textView, Config.Instance.Features.MatchFlags(Features.SyntaxHighlight))) as ITagger; } static void InitHeaderClassificationTypes() { var r = ServicesHelper.Instance.ClassificationTypeRegistry; - _HeaderClassificationTypes[1] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading1)); - _HeaderClassificationTypes[2] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading2)); - _HeaderClassificationTypes[3] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading3)); - _HeaderClassificationTypes[4] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading4)); - _HeaderClassificationTypes[5] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading5)); - _HeaderClassificationTypes[6] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading6)); + HeaderClassificationTypes[1] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading1)); + HeaderClassificationTypes[2] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading2)); + HeaderClassificationTypes[3] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading3)); + HeaderClassificationTypes[4] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading4)); + HeaderClassificationTypes[5] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading5)); + HeaderClassificationTypes[6] = new ClassificationTag(r.GetClassificationType(Constants.MarkdownHeading6)); + var dummyTag = r.GetClassificationType(Constants.CodeText); + DummyHeaderTags[1] = new ClassificationTag(dummyTag); + DummyHeaderTags[2] = new ClassificationTag(dummyTag); + DummyHeaderTags[3] = new ClassificationTag(dummyTag); + DummyHeaderTags[4] = new ClassificationTag(dummyTag); + DummyHeaderTags[5] = new ClassificationTag(dummyTag); + DummyHeaderTags[6] = new ClassificationTag(dummyTag); } sealed class MarkdownTagger : CachedTaggerBase { - public MarkdownTagger(ITextView textView) : base(textView) { + readonly ClassificationTag[] _Tags; + public MarkdownTagger(ITextView textView, bool syntaxHighlightEnabled) : base(textView) { + _Tags = syntaxHighlightEnabled ? HeaderClassificationTypes : DummyHeaderTags; } protected override bool DoFullParseAtFirstLoad => true; protected override void Parse(SnapshotSpan span, ICollection results) { @@ -62,7 +73,7 @@ protected override void Parse(SnapshotSpan span, ICollection break; } w += c; - results.Add(new TaggedContentSpan(_HeaderClassificationTypes[c], span, w, t.Length - w)); + results.Add(new TaggedContentSpan(_Tags[c], span, w, t.Length - w)); } } }