Skip to content

Commit

Permalink
- Fix Markdown syntax highlight and navibar not display correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 25, 2024
1 parent c17f95a commit 4b2988f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Codist/Taggers/CachedTaggerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ void TextView_TextBufferChanged(object sender, TextContentChangedEventArgs args)
return;
}
_Tags.PurgeOutdatedTags(args);
if (DoFullParseAtFirstLoad) {
ReparseChangedLines(args);
}
}

void ReparseChangedLines(TextContentChangedEventArgs args) {
var changedLines = new NormalizedSnapshotSpanCollection(GetLinesOfChanges(args));
if (changedLines.Count > Math.Max(1000, _TextView.TextSnapshot.LineCount / 3)) {
// if too many lines are changed, we reparse the whole document,
// when full parse is required to cache parse results
_Tags.Reset();
_Tags.Version = 0;
_TaggedContents.Clear();
ParseSnapshot();
}
else {
foreach (var dummy in GetTags(changedLines)) {
}
}
}

void TextView_Closed(object sender, EventArgs e) {
Expand All @@ -86,5 +105,24 @@ void TextView_Closed(object sender, EventArgs e) {
_Tags = null;
}
}

static IEnumerable<SnapshotSpan> GetLinesOfChanges(TextContentChangedEventArgs args) {
var ss = args.After;
int lastEnd = 0;
foreach (var item in args.Changes) {
var line = ss.GetLineFromPosition(item.NewPosition);
if (line.Start.Position < lastEnd) {
continue;
}
yield return line.Extent;
int lineEnd = line.EndIncludingLineBreak.Position;
while (lineEnd < item.NewEnd) {
line = ss.GetLineFromPosition(lineEnd);
yield return line.Extent;
lineEnd = line.EndIncludingLineBreak.Position;
}
lastEnd = lineEnd;
}
}
}
}

0 comments on commit 4b2988f

Please sign in to comment.