// CurrentRegions private static Proto.Msg.CurrentRegions CurrentRegionsToProto(CurrentRegions regions) { var p = new Proto.Msg.CurrentRegions(); foreach (var address in regions.Regions) { p.Regions.Add(AddressToProto(address)); } return(p); }
protected virtual void MainThreadAction(object backgroundProcessingResult) { if (!IsDisposed) { var result = backgroundProcessingResult as OutlineRegionsChange; if (result != null && TextRange.IsValid(result.ChangedRange)) { lock (_regionsLock) { CurrentRegions = result.NewRegions; } RegionsChanged?.Invoke(this, new OutlineRegionsChangedEventArgs(CurrentRegions.Clone() as OutlineRegionCollection, result.ChangedRange) ); } } }
protected virtual void OnTextBufferChanged(object sender, TextContentChangedEventArgs e) { // In order to provide nicer experience when user presser and holds // ENTER or DELETE or just types really fast, we are going to track // regions optimistically and report changes without going through // async or idle processing. Idle/async is still going to hit later. if (e.Changes.Count > 0) { int start, oldLength, newLength; TextUtility.CombineChanges(e, out start, out oldLength, out newLength); int changeStart = Int32.MaxValue; int changeEnd = 0; lock (_regionsLock) { // Remove affected regions and shift the remaining ones. Outlining // regions are not sorted and can overlap. Hence linear search. for (int i = 0; i < CurrentRegions.Count; i++) { var region = CurrentRegions[i]; if (region.End <= start) { continue; } if (region.Contains(start) && region.Contains(start + oldLength)) { region.Expand(0, newLength - oldLength); } else if (region.Start >= start + oldLength) { region.Shift(newLength - oldLength); } else { changeStart = Math.Min(changeStart, region.Start); changeEnd = Math.Max(changeEnd, region.End); CurrentRegions.RemoveAt(i); i--; if (e.Changes.Count > 0) { // If we merged changes, this might be an overaggressive delete. Ensure // that we'll do a full recalculation later. BackgroundTask.DoTaskOnIdle(); } } } } // If there were previously any regions, make sure we notify our listeners of the changes if ((CurrentRegions.Count > 0) || (changeStart < Int32.MaxValue)) { CurrentRegions.TextBufferVersion = TextBuffer.CurrentSnapshot.Version.VersionNumber; if (RegionsChanged != null) { changeEnd = (changeStart == Int32.MaxValue ? changeStart : changeEnd); RegionsChanged(this, new OutlineRegionsChangedEventArgs(CurrentRegions, TextRange.FromBounds(changeStart, changeEnd))); } } } }