void DisplayLines(SnapshotPoint bufferPosition, double verticalDistance, ViewRelativePosition relativeTo, double viewportWidthOverride, double viewportHeightOverride, double?newViewportTop) { if (IsClosed) { throw new InvalidOperationException(); } Dispatcher.VerifyAccess(); if (bufferPosition.Snapshot != TextSnapshot) { throw new ArgumentException(); } if (relativeTo != ViewRelativePosition.Top && relativeTo != ViewRelativePosition.Bottom) { throw new ArgumentOutOfRangeException(nameof(relativeTo)); } if (viewportHeightOverride < 0 || double.IsNaN(viewportHeightOverride)) { throw new ArgumentOutOfRangeException(nameof(viewportHeightOverride)); } if (viewportWidthOverride < 0 || double.IsNaN(viewportWidthOverride)) { throw new ArgumentOutOfRangeException(nameof(viewportWidthOverride)); } bool invalidateAllLines = false; if (viewportWidthOverride != lastViewportWidth || viewportWidthOverride != lastFormattedLineSourceViewportWidth) { invalidateAllLines = true; lastViewportWidth = viewportWidthOverride; } // Make sure the scheduled method doesn't try to call this method delayLayoutLinesInProgress = false; if (invalidateAllLines) { invalidatedRegions.Clear(); invalidatedRegions.Add(new SnapshotSpan(TextSnapshot, 0, TextSnapshot.Length)); } var regionsToInvalidate = new NormalizedSnapshotSpanCollection(invalidatedRegions.Select(a => a.TranslateTo(TextSnapshot, SpanTrackingMode.EdgeInclusive))); invalidatedRegions.Clear(); if (invalidatedRegions.Capacity > 100) { invalidatedRegions.TrimExcess(); } if (!(FormattedLineSource.SourceTextSnapshot == TextSnapshot && FormattedLineSource.TopTextSnapshot == VisualSnapshot)) { invalidateAllLines = true; } if (invalidateAllLines || formattedLineSourceIsInvalidated) { CreateFormattedLineSource(viewportWidthOverride); formattedLineSourceIsInvalidated = false; } Debug.Assert(FormattedLineSource.SourceTextSnapshot == TextSnapshot && FormattedLineSource.TopTextSnapshot == VisualSnapshot); var lineTransformProvider = LineTransformProvider; if (InLayout) { throw new InvalidOperationException(); } InLayout = true; var oldVisibleLines = new HashSet <ITextViewLine>(wpfTextViewLineCollection == null ? (IList <ITextViewLine>)Array.Empty <ITextViewLine>() : wpfTextViewLineCollection); wpfTextViewLineCollection?.Invalidate(); var layoutHelper = new LayoutHelper(lineTransformProvider, newViewportTop ?? 0, oldVisibleLines, GetValidCachedLines(regionsToInvalidate), FormattedLineSource, TextViewModel, VisualSnapshot, TextSnapshot); layoutHelper.LayoutLines(bufferPosition, relativeTo, verticalDistance, ViewportLeft, viewportWidthOverride, viewportHeightOverride); visiblePhysicalLines.AddRange(layoutHelper.AllVisiblePhysicalLines); wpfTextViewLineCollection = new WpfTextViewLineCollection(this, TextSnapshot, layoutHelper.AllVisibleLines); if (!InLayout) { throw new InvalidOperationException(); } InLayout = false; textLayer.AddVisibleLines(layoutHelper.AllVisibleLines); var newOrReformattedLines = layoutHelper.NewOrReformattedLines.ToArray(); var translatedLines = layoutHelper.TranslatedLines.ToArray(); if (layoutHelper.NewViewportTop != viewportTop) { viewportTop = layoutHelper.NewViewportTop; SetTop(normalAdornmentLayerCollection, -viewportTop); } RaiseLayoutChanged(viewportWidthOverride, viewportHeightOverride, newOrReformattedLines, translatedLines); }
void DisplayLines(SnapshotPoint bufferPosition, double verticalDistance, ViewRelativePosition relativeTo, double viewportWidthOverride, double viewportHeightOverride, double? newViewportTop) { if (IsClosed) throw new InvalidOperationException(); Dispatcher.VerifyAccess(); if (bufferPosition.Snapshot != TextSnapshot) throw new ArgumentException(); if (relativeTo != ViewRelativePosition.Top && relativeTo != ViewRelativePosition.Bottom) throw new ArgumentOutOfRangeException(nameof(relativeTo)); if (viewportHeightOverride < 0 || double.IsNaN(viewportHeightOverride)) throw new ArgumentOutOfRangeException(nameof(viewportHeightOverride)); if (viewportWidthOverride < 0 || double.IsNaN(viewportWidthOverride)) throw new ArgumentOutOfRangeException(nameof(viewportWidthOverride)); bool invalidateAllLines = false; if (viewportWidthOverride != lastViewportWidth || viewportWidthOverride != lastFormattedLineSourceViewportWidth) { invalidateAllLines = true; lastViewportWidth = viewportWidthOverride; } // Make sure the scheduled method doesn't try to call this method delayLayoutLinesInProgress = false; if (invalidateAllLines) { invalidatedRegions.Clear(); invalidatedRegions.Add(new SnapshotSpan(TextSnapshot, 0, TextSnapshot.Length)); } var regionsToInvalidate = new NormalizedSnapshotSpanCollection(invalidatedRegions.Select(a => a.TranslateTo(TextSnapshot, SpanTrackingMode.EdgeInclusive))); invalidatedRegions.Clear(); if (invalidatedRegions.Capacity > 100) invalidatedRegions.TrimExcess(); if (!(FormattedLineSource.SourceTextSnapshot == TextSnapshot && FormattedLineSource.TopTextSnapshot == VisualSnapshot)) invalidateAllLines = true; if (invalidateAllLines || formattedLineSourceIsInvalidated) { CreateFormattedLineSource(viewportWidthOverride); formattedLineSourceIsInvalidated = false; } Debug.Assert(FormattedLineSource.SourceTextSnapshot == TextSnapshot && FormattedLineSource.TopTextSnapshot == VisualSnapshot); var lineTransformProvider = LineTransformProvider; if (InLayout) throw new InvalidOperationException(); InLayout = true; var oldVisibleLines = new HashSet<ITextViewLine>(wpfTextViewLineCollection == null ? (IList<ITextViewLine>)Array.Empty<ITextViewLine>() : wpfTextViewLineCollection); wpfTextViewLineCollection?.Invalidate(); var layoutHelper = new LayoutHelper(lineTransformProvider, newViewportTop ?? 0, oldVisibleLines, GetValidCachedLines(regionsToInvalidate), FormattedLineSource, TextViewModel, VisualSnapshot, TextSnapshot); layoutHelper.LayoutLines(bufferPosition, relativeTo, verticalDistance, ViewportLeft, viewportWidthOverride, viewportHeightOverride); visiblePhysicalLines.AddRange(layoutHelper.AllVisiblePhysicalLines); wpfTextViewLineCollection = new WpfTextViewLineCollection(this, TextSnapshot, layoutHelper.AllVisibleLines); if (!InLayout) throw new InvalidOperationException(); InLayout = false; textLayer.AddVisibleLines(layoutHelper.AllVisibleLines); var newOrReformattedLines = layoutHelper.NewOrReformattedLines.ToArray(); var translatedLines = layoutHelper.TranslatedLines.ToArray(); if (layoutHelper.NewViewportTop != viewportTop) { viewportTop = layoutHelper.NewViewportTop; SetTop(normalAdornmentLayerCollection, -viewportTop); } RaiseLayoutChanged(viewportWidthOverride, viewportHeightOverride, newOrReformattedLines, translatedLines); }