public void ApplyEdits(params TestEdit[] edits)
        {
            if (edits.Length == 0)
            {
                return;
            }

            var args = new TextContentChangedEventArgs(edits[0].OldSnapshot, edits[edits.Length - 1].NewSnapshot, new EditOptions(), null);

            foreach (var edit in edits)
            {
                args.Changes.Add(new TestTextChange(edit.Change));
            }

            CurrentSnapshot = edits[edits.Length - 1].NewSnapshot;
            if (CurrentSnapshot is StringTextSnapshot testSnapshot)
            {
                testSnapshot.TextBuffer = this;
            }

            foreach (var changedEvent in AttachedChangedEvents)
            {
                changedEvent.Invoke(this, args);
            }

            PostChanged?.Invoke(this, null);

            ReadOnlyRegionsChanged?.Invoke(this, null);
            ChangedLowPriority?.Invoke(this, null);
            ChangedHighPriority?.Invoke(this, null);
            Changing?.Invoke(this, null);
        }
Esempio n. 2
0
        private void FireChanged(int start, int oldLength, int newLength)
        {
            var oldTextProvider = new TextStream(CurrentSnapshot.GetText());

            _version++;
            _currentSnapshot = new EditorBufferSnapshot(this, _content.ToString(), _version);

            var newTextProvider = new TextStream(_currentSnapshot.GetText());
            var change          = new TextChange(start, oldLength, newLength, oldTextProvider, newTextProvider);
            var args            = new TextChangeEventArgs(change);

            ChangedHighPriority?.Invoke(this, args);
            Changed?.Invoke(this, args);
        }
Esempio n. 3
0
        internal void ApplyChanges(TextEdit textEdit, List <ITextChange> changes, EditOptions options, int?reiteratedVersionNumber, object editTag)
        {
            VerifyAccess();
            if (textEdit != textEditInProgress)
            {
                throw new InvalidOperationException();
            }
            textEditInProgress = null;

            if (RaiseChangingGetIsCanceled(editTag))
            {
                PostChanged?.Invoke(this, EventArgs.Empty);
                return;
            }

            if (changes.Count != 0)
            {
                // We don't support overlapping changes. All offsets are relative to the original buffer
                changes.Sort((a, b) => b.OldPosition - a.OldPosition);
                for (int i = 1; i < changes.Count; i++)
                {
                    if (changes[i - 1].OldSpan.OverlapsWith(changes[i].OldSpan))
                    {
                        throw new InvalidOperationException("Two edit operations overlap");
                    }
                }

                var beforeSnapshot = CurrentSnapshot;
                Document.BeginUpdate();
                // changes is sorted in reverse order by OldPosition
                foreach (var change in changes)
                {
                    Document.Replace(change.OldPosition, change.OldLength, change.NewText);
                }
                Document.EndUpdate();
                CreateNewCurrentSnapshot(changes, afterTextSource: Document.CreateSnapshot());
                var afterSnapshot = CurrentSnapshot;

                TextContentChangedEventArgs args = null;
                //TODO: The event handlers are allowed to modify the buffer, but the new events must only be
                //		raised after all of these three events have been raised.
                ChangedHighPriority?.Invoke(this, args ?? (args = new TextContentChangedEventArgs(beforeSnapshot, afterSnapshot, options, editTag)));
                Changed?.Invoke(this, args ?? (args = new TextContentChangedEventArgs(beforeSnapshot, afterSnapshot, options, editTag)));
                ChangedLowPriority?.Invoke(this, args ?? (args = new TextContentChangedEventArgs(beforeSnapshot, afterSnapshot, options, editTag)));
            }
            //TODO: Use reiteratedVersionNumber
            PostChanged?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 4
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);
        }
            public void ApplyEdit(TestEdit edit)
            {
                var args = new TextContentChangedEventArgs(edit.OldSnapshot, edit.NewSnapshot, new EditOptions(), null);

                args.Changes.Add(new TextChange(edit));
                Changed?.Invoke(this, args);

                ReadOnlyRegionsChanged?.Invoke(null, null);
                ChangedLowPriority?.Invoke(null, null);
                ChangedHighPriority?.Invoke(null, null);
                Changing?.Invoke(null, null);
                PostChanged?.Invoke(null, null);
                ContentTypeChanged?.Invoke(null, null);

                _currentSnapshot = edit.NewSnapshot;
            }
Esempio n. 6
0
        internal void ApplyChanges(HexEditImpl hexEdit, List <HexChange> changes, int?reiteratedVersionNumber, object editTag)
        {
            VerifyAccess();
            if (hexEdit != hexEditInProgress)
            {
                throw new InvalidOperationException();
            }
            hexEditInProgress = null;

            if (RaiseChangingGetIsCanceled(editTag))
            {
                PostChanged?.Invoke(this, EventArgs.Empty);
                return;
            }

            if (changes.Count != 0)
            {
                // We don't support overlapping changes. All offsets are relative to the original buffer
                changes.Sort(ReverseOldPositionSorter.Instance);
                for (int i = 1; i < changes.Count; i++)
                {
                    if (changes[i - 1].OldSpan.OverlapsWith(changes[i].OldSpan))
                    {
                        throw new InvalidOperationException("Two edit operations overlap");
                    }
                }

                var beforeVersion = Version;
                // changes is sorted in reverse order by OldPosition
                foreach (var change in changes)
                {
                    stream.Write(change.OldPosition, change.NewData);
                }
                CreateNewVersion(changes, reiteratedVersionNumber);
                var afterVersion = Version;

                HexContentChangedEventArgs args = null;
                //TODO: The event handlers are allowed to modify the buffer, but the new events must only be
                //		raised after all of these three events have been raised.
                ChangedHighPriority?.Invoke(this, args ?? (args = new HexContentChangedEventArgs(beforeVersion, afterVersion, editTag)));
                Changed?.Invoke(this, args ?? (args = new HexContentChangedEventArgs(beforeVersion, afterVersion, editTag)));
                ChangedLowPriority?.Invoke(this, args ?? (args = new HexContentChangedEventArgs(beforeVersion, afterVersion, editTag)));
            }
            PostChanged?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 7
0
        public void ApplyEdits(params TestEdit[] edits)
        {
            var args = new TextContentChangedEventArgs(edits[0].OldSnapshot, edits[edits.Length - 1].NewSnapshot, new EditOptions(), null);

            foreach (var edit in edits)
            {
                args.Changes.Add(new TestTextChange(edit.Change));
            }

            _currentSnapshot = edits[edits.Length - 1].NewSnapshot;

            foreach (var changedEvent in AttachedChangedEvents)
            {
                changedEvent.Invoke(this, args);
            }

            PostChanged?.Invoke(null, null);

            ReadOnlyRegionsChanged?.Invoke(null, null);
            ChangedLowPriority?.Invoke(null, null);
            ChangedHighPriority?.Invoke(null, null);
            Changing?.Invoke(null, null);
            ContentTypeChanged?.Invoke(null, null);
        }
Esempio n. 8
0
 private void OnTextBufferChangedHighPriority(object sender, TextContentChangedEventArgs e)
 => ChangedHighPriority?.Invoke(this, new TextChangeEventArgs(e.ToTextChange()));