Beispiel #1
0
        public TextChangeContext(EditorTree editorTree, TextChangeEventArgs change, TextChange pendingChanges)
        {
            EditorTree = editorTree;
            NewStart = change.Start;
            OldStart = change.OldStart;
            OldLength = change.OldLength;
            NewLength = change.NewLength;

            OldTextProvider = change.OldText != null ? change.OldText : editorTree.AstRoot.TextProvider;
            NewTextProvider = change.NewText != null ? change.NewText : new TextProvider(editorTree.TextBuffer.CurrentSnapshot, partial: true);

            PendingChanges = pendingChanges;

            TextChange textChange = new TextChange();

            textChange.OldRange = this.OldRange;
            textChange.OldTextProvider = this.OldTextProvider;

            textChange.NewRange = this.NewRange;
            textChange.NewTextProvider = this.NewTextProvider;

            textChange.Version = this.NewTextProvider.Version;

            PendingChanges.Combine(textChange);
        }
Beispiel #2
0
        /// <summary>
        /// Converts list of text changes in a text buffer to a collection of 
        /// changes that are relative one to another. 
        /// </summary>
        /// <param name="changes">Sorted collection of changes</param>
        /// <returns>Collection of relative changes</returns>
        public static IReadOnlyList<TextChangeEventArgs> ConvertToRelative(this TextContentChangedEventArgs changeInfo) {
            IList<ITextChange> changes = changeInfo.Changes;
            var list = new List<TextChangeEventArgs>(changes.Count);
            ITextChange previousChange = null;
            TextProvider oldText = new TextProvider(changeInfo.Before, true);
            TextProvider newText = new TextProvider(changeInfo.After, true);

            for (int i = 0; i < changes.Count; i++) {
                var change = changes[i];

                if (previousChange != null) {
                    if (previousChange.OldEnd > change.OldPosition || previousChange.NewEnd > change.NewPosition)
                        throw new ArgumentException("List of changes must not overlap", "changes");
                }

                var textChange = new TextChangeEventArgs(change.NewPosition, change.OldPosition, change.OldLength, change.NewLength, oldText, newText);
                list.Add(textChange);

                previousChange = change;
            }

            return list;
        }
Beispiel #3
0
        /// <summary>
        /// Tells document that massive change to text buffer is complete. Document will perform full parse, 
        /// resume tracking of text buffer changes and classification (colorization).
        /// </summary>
        /// <returns>True if changes were made to the text buffer since call to BeginMassiveChange</returns>
        public bool EndMassiveChange() {
            bool changed = _editorTree.TreeUpdateTask.TextBufferChangedSinceSuspend;

            if (_inMassiveChange == 1) {
                var colorizer = ServiceManager.GetService<RClassifier>(TextBuffer);
                colorizer?.Resume();

                if (changed) {
                    TextChangeEventArgs textChange =
                        new TextChangeEventArgs(0, 0, TextBuffer.CurrentSnapshot.Length, 0,
                            new TextProvider(_editorTree.TextSnapshot, partial: true),
                            new TextStream(string.Empty));

                    List<TextChangeEventArgs> textChanges = new List<TextChangeEventArgs>();
                    textChanges.Add(textChange);
                    _editorTree.FireOnUpdatesPending(textChanges);
                }

                _editorTree.TreeUpdateTask.Resume();
                MassiveChangeEnded?.Invoke(this, EventArgs.Empty);
            }

            if (_inMassiveChange > 0) {
                _inMassiveChange--;
            }

            return changed;
        }
Beispiel #4
0
        internal void NotifyTextChange(int start, int oldLength, int newLength) {
            TextChangeEventArgs change = new TextChangeEventArgs(start, start, oldLength, newLength);
            List<TextChangeEventArgs> changes = new List<TextChangeEventArgs>(1);
            changes.Add(change);

            NotifyTextChanges(changes);
        }
Beispiel #5
0
        internal void NotifyTextChange(int start, int oldLength, int newLength) {
            TextChangeEventArgs change = new TextChangeEventArgs(start, start, oldLength, newLength);
            List<TextChangeEventArgs> changes = new List<TextChangeEventArgs>(1);
            changes.Add(change);

            _astRoot.ReflectTextChanges(changes, new TextProvider(TextBuffer.CurrentSnapshot));
        }