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

SwapAnchors() private method

Swaps the anchors stored in the two nodes.
private SwapAnchors ( TextAnchorNode n1, TextAnchorNode n2 ) : void
n1 TextAnchorNode
n2 TextAnchorNode
return void
		private void SwapAnchors(TextAnchorNode n1, TextAnchorNode n2)
		{
			if (n1 != n2)
			{
				var anchor1 = (TextAnchor) n1.Target;
				var anchor2 = (TextAnchor) n2.Target;
				if (anchor1 == null && anchor2 == null)
				{
					// -> no swap required
					return;
				}
				n1.Target = anchor2;
				n2.Target = anchor1;
				if (anchor1 == null)
				{
					// unmark n1 from deletion, mark n2 for deletion
					nodesToDelete.Remove(n1);
					MarkNodeForDelete(n2);
					anchor2.node = n1;
				}
				else if (anchor2 == null)
				{
					// unmark n2 from deletion, mark n1 for deletion
					nodesToDelete.Remove(n2);
					MarkNodeForDelete(n1);
					anchor1.node = n2;
				}
				else
				{
					anchor1.node = n2;
					anchor2.node = n1;
				}
			}
		}