private void Update(SnapshotPoint snapPt, NormalizedSnapshotSpanCollection wordSpans) { var parser = new BraceHighlightParser(); var spans = parser.FindMatchingBraces(snapPt.Snapshot, snapPt.Position).ToArray(); var changed = false; var oldBraceSpans = _braceSpans; var oldWordSpans = _wordSpans; SnapshotSpan?updateSpan = null; lock (_updateLock) { if (wordSpans != _wordSpans) { _wordSpans = wordSpans; changed = true; } if (spans.Length < 2) { if (_braceSpans != null) { _braceSpans = null; changed = true; } } else { _braceSpans = new NormalizedSnapshotSpanCollection((from s in spans select new SnapshotSpan(snapPt.Snapshot, s.Start.Position, s.End.Position - s.Start.Position))); changed = true; } if (changed) { updateSpan = null; if (oldBraceSpans != null) { updateSpan = oldBraceSpans.EncompassingSpan(); } if (oldWordSpans != null) { updateSpan = updateSpan.HasValue ? updateSpan.EncompassingSpan(oldWordSpans) : oldWordSpans.EncompassingSpan(); } if (_braceSpans != null) { updateSpan = updateSpan.HasValue ? updateSpan.EncompassingSpan(_braceSpans) : _braceSpans.EncompassingSpan(); } if (_wordSpans != null) { updateSpan = updateSpan.HasValue ? updateSpan.EncompassingSpan(_wordSpans) : _wordSpans.EncompassingSpan(); } _updateSpan = null; if (_braceSpans != null) { _updateSpan = _braceSpans.EncompassingSpan(); } if (_wordSpans != null) { _updateSpan = _updateSpan.HasValue ? _updateSpan.EncompassingSpan(_wordSpans) : _wordSpans.EncompassingSpan(); } } } if (changed && updateSpan.HasValue) { var ev = TagsChanged; if (ev != null) { ev(this, new SnapshotSpanEventArgs(updateSpan.Value)); } } }