Inheritance: ITextSnapshot
示例#1
0
        public TextBufferMock(string content, string contentTypeName)
        {
            ContentType = new ContentTypeMock(contentTypeName, new IContentType[] { ContentTypeMock.TextContentType });
            TextVersionMock initialVersion = new TextVersionMock(this, 0, content.Length);

            CurrentSnapshot = new TextSnapshotMock(content, this, initialVersion);
        }
示例#2
0
        public TextSnapshotMock CreateNextSnapshot(string content, TextChangeMock change) {
            Change = change;
            TextVersionMock nextVersion = _version.CreateNextVersion(change);
            TextSnapshotMock nextSnapshot = new TextSnapshotMock(content, TextBuffer, nextVersion);

            return nextSnapshot;
        }
示例#3
0
        public TextSnapshotMock CreateNextSnapshot(string content, TextChangeMock change)
        {
            Change = change;
            TextVersionMock  nextVersion  = _version.CreateNextVersion(change);
            TextSnapshotMock nextSnapshot = new TextSnapshotMock(content, TextBuffer, nextVersion);

            return(nextSnapshot);
        }
示例#4
0
        public ITextSnapshot Delete(Span deleteSpan)
        {
            var sb      = new StringBuilder();
            var oldText = CurrentSnapshot.GetText(deleteSpan.Start, deleteSpan.Length);

            sb.Append(CurrentSnapshot.GetText(0, deleteSpan.Start));
            sb.Append(CurrentSnapshot.GetText(deleteSpan.End, CurrentSnapshot.Length - deleteSpan.End));

            TextChangeMock   change       = new TextChangeMock(deleteSpan.Start, deleteSpan.Length, oldText, String.Empty);
            TextSnapshotMock nextSnapshot = ((TextSnapshotMock)CurrentSnapshot).CreateNextSnapshot(sb.ToString(), change);

            ApplyChange(nextSnapshot);

            return(CurrentSnapshot);
        }
示例#5
0
        public ITextSnapshot Insert(int position, string text)
        {
            var sb = new StringBuilder();

            sb.Append(CurrentSnapshot.GetText(0, position));
            sb.Append(text);
            sb.Append(CurrentSnapshot.GetText(position, CurrentSnapshot.Length - position));

            TextChangeMock   change       = new TextChangeMock(position, 0, String.Empty, text);
            TextSnapshotMock nextSnapshot = ((TextSnapshotMock)CurrentSnapshot).CreateNextSnapshot(sb.ToString(), change);

            ApplyChange(nextSnapshot);

            return(CurrentSnapshot);
        }
示例#6
0
        private void ApplyChange(TextSnapshotMock snapshot)
        {
            Changing?.Invoke(this, new TextContentChangingEventArgs(CurrentSnapshot, new object(), CancelAction));

            var before = CurrentSnapshot;

            CurrentSnapshot = snapshot;

            var args = new TextContentChangedEventArgs(before, CurrentSnapshot, EditOptions.None, new object());

            BeforeChanged?.Invoke(this, args);
            ChangedHighPriority?.Invoke(this, args);
            Changed?.Invoke(this, args);
            ChangedLowPriority?.Invoke(this, args);
            PostChanged?.Invoke(this, EventArgs.Empty);
        }
示例#7
0
        public ITextSnapshot Replace(Span replaceSpan, string replaceWith)
        {
            var sb      = new StringBuilder();
            var oldText = CurrentSnapshot.GetText(replaceSpan);

            sb.Append(CurrentSnapshot.GetText(0, replaceSpan.Start));
            sb.Append(replaceWith);
            sb.Append(CurrentSnapshot.GetText(replaceSpan.End, CurrentSnapshot.Length - replaceSpan.End));

            TextChangeMock change = new TextChangeMock(replaceSpan.Start, replaceSpan.Length, oldText, replaceWith);

            TextSnapshotMock nextSnapshot = ((TextSnapshotMock)CurrentSnapshot).CreateNextSnapshot(sb.ToString(), change);

            ApplyChange(nextSnapshot);

            return(CurrentSnapshot);
        }
示例#8
0
        private void ApplyChange(TextSnapshotMock snapshot)
        {
            if (Changing != null)
            {
                Changing(this, new TextContentChangingEventArgs(CurrentSnapshot, new object(), CancelAction));
            }

            var before = CurrentSnapshot;

            CurrentSnapshot = snapshot;

            var args = new TextContentChangedEventArgs(before, CurrentSnapshot, EditOptions.None, new object());

            if (BeforeChanged != null)
            {
                BeforeChanged(this, args);
            }

            if (ChangedHighPriority != null)
            {
                ChangedHighPriority(this, args);
            }

            if (Changed != null)
            {
                Changed(this, args);
            }

            if (ChangedLowPriority != null)
            {
                ChangedLowPriority(this, args);
            }

            if (PostChanged != null)
            {
                PostChanged(this, EventArgs.Empty);
            }
        }
示例#9
0
        private void ApplyChange(TextSnapshotMock snapshot)
        {
            if (Changing != null)
                Changing(this, new TextContentChangingEventArgs(CurrentSnapshot, new object(), CancelAction));

            var before = CurrentSnapshot;
            CurrentSnapshot = snapshot;

            var args = new TextContentChangedEventArgs(before, CurrentSnapshot, EditOptions.None, new object());

            if (BeforeChanged != null)
                BeforeChanged(this, args);

            if (ChangedHighPriority != null)
                ChangedHighPriority(this, args);

            if (Changed != null)
                Changed(this, args);

            if (ChangedLowPriority != null)
                ChangedLowPriority(this, args);

            if (PostChanged != null)
                PostChanged(this, EventArgs.Empty);
        }
示例#10
0
 public TextBufferMock(string content, string contentTypeName)
 {
     ContentType = new ContentTypeMock(contentTypeName, new IContentType[] { ContentTypeMock.TextContentType });
     TextVersionMock initialVersion = new TextVersionMock(this, 0, content.Length);
     CurrentSnapshot = new TextSnapshotMock(content, this, initialVersion);
 }