Пример #1
0
        private void SetReadOnlyRegionType(ReadOnlyRegionType value)
        {
            ITextBuffer   buffer   = WpfTextView.TextBuffer;
            ITextSnapshot snapshot = buffer.CurrentSnapshot;

            using (IReadOnlyRegionEdit edit = buffer.CreateReadOnlyRegionEdit()) {
                edit.ClearReadOnlyRegion(ref _readOnlyRegionBegin);
                edit.ClearReadOnlyRegion(ref _readOnlyRegionBody);

                switch (value)
                {
                case ReadOnlyRegionType.BeginAndBody:
                    if (snapshot.Length > 0)
                    {
                        _readOnlyRegionBegin = edit.CreateReadOnlyRegion(new Span(0, 0), SpanTrackingMode.EdgeExclusive, EdgeInsertionMode.Deny);
                        _readOnlyRegionBody  = edit.CreateReadOnlyRegion(new Span(0, snapshot.Length));
                    }
                    break;

                case ReadOnlyRegionType.All:
                    _readOnlyRegionBody = edit.CreateReadOnlyRegion(new Span(0, snapshot.Length), SpanTrackingMode.EdgeExclusive, EdgeInsertionMode.Deny);
                    break;
                }

                edit.Apply();
            }
        }
 /// <summary>
 /// Removes a ReadOnlyRegion and clears the reference (set to null).
 /// </summary>
 public static void ClearReadOnlyRegion(this IReadOnlyRegionEdit readOnlyRegionEdit, ref IReadOnlyRegion readOnlyRegion)
 {
     if (readOnlyRegion != null)
     {
         readOnlyRegionEdit.RemoveReadOnlyRegion(readOnlyRegion);
         readOnlyRegion = null;
     }
 }