Skip to content

Instantly share code, notes, and snippets.

@NoahRic
Created February 25, 2010 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoahRic/314792 to your computer and use it in GitHub Desktop.
Save NoahRic/314792 to your computer and use it in GitHub Desktop.
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