Microsoft.R.Editor.Tree.TreeUpdateTask.OnTextChanges C# (CSharp) Method

OnTextChanges() private method

Text buffer change event handler. Performs analysis of the change. If change is trivial, such as change in whitespace (excluding line breaks that in R may be sensistive), simply applies the changes by shifting tree elements. If some elements get deleted or otherwise damaged, removes them from the tree right away. Non-trivial changes are queued for background parsing which starts on next on idle. Methond must be called on a main thread only, typically from an event handler that receives text buffer change events.
private OnTextChanges ( IReadOnlyCollection textChanges ) : void
textChanges IReadOnlyCollection
return void
        internal void OnTextChanges(IReadOnlyCollection<TextChangeEventArgs> textChanges) {
            if (Thread.CurrentThread.ManagedThreadId != _ownerThreadId)
                throw new ThreadStateException("Method should only be called on the main thread");

            _editorTree.FireOnUpdatesPending(textChanges);
            if (UpdatesSuspended) {
                this.TextBufferChangedSinceSuspend = true;
                _pendingChanges.FullParseRequired = true;
            } else {
                foreach (TextChangeEventArgs change in textChanges) {
                    _lastChangeTime = DateTime.UtcNow;
                    var context = new TextChangeContext(_editorTree, change, _pendingChanges);

                    // No need to analyze changes if full parse is already pending
                    if (!_pendingChanges.FullParseRequired) {
                        TextChangeAnalyzer.DetermineChangeType(context);
                    }

                    ProcessChange(context);
                }
            }
        }

Usage Example

Example #1
0
 private void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
 {
     if (e.Changes.Count > 0)
     {
         // In case of tabbing multiple lines update comes as multiple changes
         // each is an insertion of whitespace in the beginning of the line.
         // We don't want to combine them since then change will technically
         // damage existing elements while actually it is just a whitespace change.
         // All changes are relative to the current snapshot hence we have to transform
         // them first and make them relative to each other so we can apply changes
         // sequentially as after every change element positions will shift and hence
         // next change must be relative to the new position and not to the current
         // text buffer snapshot. Changes are sorted by position.
         TreeUpdateTask.OnTextChanges(e.ConvertToRelative());
     }
 }