AvalonStudio.TextEditor.Document.TextAnchorTree.PerformInsertText C# (CSharp) Method

PerformInsertText() private method

private PerformInsertText ( TextAnchorNode beginNode, TextAnchorNode endNode, int length, bool defaultAnchorMovementIsBeforeInsertion ) : void
beginNode TextAnchorNode
endNode TextAnchorNode
length int
defaultAnchorMovementIsBeforeInsertion bool
return void
		private void PerformInsertText(TextAnchorNode beginNode, TextAnchorNode endNode, int length,
			bool defaultAnchorMovementIsBeforeInsertion)
		{
			Debug.Assert(beginNode != null);
			// endNode may be null at the end of the anchor tree

			// now we need to sort the nodes in the range [beginNode, endNode); putting those with
			// MovementType.BeforeInsertion in front of those with MovementType.AfterInsertion
			var beforeInsert = new List<TextAnchorNode>();
			//List<TextAnchorNode> afterInsert = new List<TextAnchorNode>();
			var temp = beginNode;
			while (temp != endNode)
			{
				var anchor = (TextAnchor) temp.Target;
				if (anchor == null)
				{
					// afterInsert.Add(temp);
					MarkNodeForDelete(temp);
				}
				else if (defaultAnchorMovementIsBeforeInsertion
					? anchor.MovementType != AnchorMovementType.AfterInsertion
					: anchor.MovementType == AnchorMovementType.BeforeInsertion)
				{
					beforeInsert.Add(temp);
					//				} else {
					//					afterInsert.Add(temp);
				}
				temp = temp.Successor;
			}
			// now again go through the range and swap the nodes with those in the beforeInsert list
			temp = beginNode;
			foreach (var node in beforeInsert)
			{
				SwapAnchors(node, temp);
				temp = temp.Successor;
			}
			// now temp is pointing to the first node that is afterInsert,
			// or to endNode, if there is no afterInsert node at the offset
			// So add the length to temp
			if (temp == null)
			{
				// temp might be null if endNode==null and no afterInserts
				Debug.Assert(endNode == null);
			}
			else
			{
				temp.length += length;
				UpdateAugmentedData(temp);
			}
		}