Skip to content

Instantly share code, notes, and snippets.

@NoahRic
Created February 25, 2010 17:41
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/314798 to your computer and use it in GitHub Desktop.
Save NoahRic/314798 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)
}));
NormalizedSnapshotSpanCollection oldSectionSpans = new NormalizedSnapshotSpanCollection(
_sections.Select(s => s.Span.GetSpan(snapshot)));
NormalizedSnapshotSpanCollection newSectionSpans = new NormalizedSnapshotSpanCollection(
newSections.Select(s => s.Span.GetSpan(snapshot)));
NormalizedSnapshotSpanCollection difference = NormalizedSnapshotSpanCollection.Difference(oldSectionSpans, newSectionSpans);
_sections = newSections;
var temp = TagsChanged;
if (temp != null && difference.Count > 0)
{
temp(this, new SnapshotSpanEventArgs(new SnapshotSpan(difference[0].Start, difference[difference.Count - 1].End)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment