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

DeleteAndShiftElements() private method

private DeleteAndShiftElements ( TextChangeContext context ) : bool
context TextChangeContext
return bool
        internal bool DeleteAndShiftElements(TextChangeContext context) {
            if (Thread.CurrentThread.ManagedThreadId != _ownerThreadId)
                throw new ThreadStateException("Method should only be called on the main thread");

            TextChange textChange = context.PendingChanges;
            var changeType = textChange.TextChangeType;
            bool elementsChanged = false;

            if (changeType == TextChangeType.Structure) {
                IAstNode changedElement = context.ChangedNode;
                int start = context.NewStart;

                // We delete change nodes unless node is a token node 
                // which range can be modified such as string or comment
                var positionType = PositionType.Undefined;

                if (changedElement != null) {
                    IAstNode node;
                    positionType = changedElement.GetPositionNode(context.NewStart, out node);
                }

                bool deleteElements = (context.OldLength > 0) || (positionType != PositionType.Token);

                // In case of delete or replace we need to invalidate elements that were 
                // damaged by the delete operation. We need to remove elements so they 
                // won't be found by validator and it won't be looking at zombies.
                if (deleteElements) {
                    _pendingChanges.FullParseRequired = true;
                    elementsChanged = _editorTree.InvalidateInRange(context.OldRange);
                }
            }

            _editorTree.NotifyTextChange(context.NewStart, context.OldLength, context.NewLength);
            return elementsChanged;
        }