public void AddRegisterDirective(RegisterDirective directive, TextEditor editor, bool preserveCaretPosition)
        {
            var node = GetRegisterInsertionPointNode();

            if (node == null)
            {
                return;
            }

            Doc.Info.RegisteredTags.Add(directive);

            var line = Math.Max(node.Location.EndLine, node.Location.BeginLine);
            var pos  = editor.GetPositionFromLineColumn(line, editor.GetLineLength(line) + 1);

            if (pos < 0)
            {
                return;
            }

            editor.BeginAtomicUndo();
            var oldCaret = editor.CursorPosition;

            var inserted = editor.InsertText(pos, editor.NewLine + directive.ToString());

            if (preserveCaretPosition)
            {
                editor.CursorPosition = (pos < oldCaret)? oldCaret + inserted : oldCaret;
            }
            editor.EndAtomicUndo();
        }