public void SetProjectionMappings(string secondaryContent, IReadOnlyList <ProjectionMapping> mappings)
        {
            // Changing projections can move caret to a visible area unexpectedly.
            // Save caret position so we can place it at the same location when
            // projections are re-established.
            SaveViewPosition();

            var secondarySpans = CreateSecondarySpans(secondaryContent, mappings);

            if (IdenticalSpans(secondarySpans))
            {
                return;
            }

            // While we are changing mappings map everything to the view
            mappings = mappings ?? new List <ProjectionMapping>();
            MapEverythingToView();

            // Now update language spans
            ContainedLanguageBuffer.ReplaceSpans(0, ContainedLanguageBuffer.CurrentSnapshot.SpanCount, secondarySpans, EditOptions.DefaultMinimalChange, this);
            if (secondarySpans.Count > 0)
            {
                // Update primary (view) buffer projected spans. View buffer spans are all tracking spans:
                // they either come from primary content or secondary content. Inert spans do not participate.
                var viewSpans = CreateViewSpans(mappings);
                if (viewSpans.Count > 0)
                {
                    ViewBuffer.ReplaceSpans(0, ViewBuffer.CurrentSnapshot.SpanCount, viewSpans, EditOptions.DefaultMinimalChange, this);
                }
            }

            RestoreViewPosition();
            MappingsChanged?.Invoke(this, EventArgs.Empty);
        }
        private void MapEverythingToView()
        {
            var diskSnap     = DiskBuffer.CurrentSnapshot;
            var everything   = new SnapshotSpan(diskSnap, 0, diskSnap.Length);
            var trackingSpan = diskSnap.CreateTrackingSpan(everything, SpanTrackingMode.EdgeInclusive);

            ViewBuffer.ReplaceSpans(0, ViewBuffer.CurrentSnapshot.SpanCount, new List <object>()
            {
                trackingSpan
            }, EditOptions.None, this);
        }
        public void SetProjectionMappings(string secondaryContent, IReadOnlyList <ProjectionMapping> mappings)
        {
            mappings = mappings ?? new List <ProjectionMapping>();
            MapEverythingToView();

            // Now update language spans
            var secondarySpans = CreateSecondarySpans(secondaryContent, mappings);

            ContainedLanguageBuffer.ReplaceSpans(0, ContainedLanguageBuffer.CurrentSnapshot.SpanCount, secondarySpans, EditOptions.DefaultMinimalChange, this);

            // Update primary (view) buffer projected spans. View buffer spans are all tracking spans:
            // they either come from primary content or secondary content. Inert spans do not participate.
            var viewSpans = CreateViewSpans(mappings);

            if (viewSpans.Count > 0)
            {
                ViewBuffer.ReplaceSpans(0, ViewBuffer.CurrentSnapshot.SpanCount, viewSpans, EditOptions.DefaultMinimalChange, this);
            }
        }