Created
February 25, 2010 17:37
-
-
Save NoahRic/314792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ReparseFile(object sender, EventArgs args) | |
{ | |
ITextSnapshot snapshot = _buffer.CurrentSnapshot; | |
List<MarkdownSection> newSections = new List<MarkdownSection>( | |
MarkdownParser.ParseMarkdownSections(snapshot) | |
.Select(t => new MarkdownSection() | |
{ | |
TokenType = t.TokenType, | |
Span = snapshot.CreateTrackingSpan(t.Span, SpanTrackingMode.EdgeExclusive) | |
})); | |
var oldSectionSpans = new NormalizedSnapshotSpanCollection( | |
_sections.Select(s => s.Span.GetSpan(snapshot))); | |
var newSectionSpans = new NormalizedSnapshotSpanCollection( | |
newSections.Select(s => s.Span.GetSpan(snapshot))); | |
var first = NormalizedSnapshotSpanCollection.Difference(oldSectionSpans, newSectionSpans); | |
var second = NormalizedSnapshotSpanCollection.Difference(newSectionSpans, oldSectionSpans); | |
var difference = NormalizedSnapshotSpanCollection.Union(first, second); | |
_sections = newSections; | |
foreach (var span in difference) | |
{ | |
var temp = TagsChanged; | |
if (temp != null) | |
temp(this, new SnapshotSpanEventArgs(span)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment