Insert() public method

Inserts text.
Anchors positioned exactly at the insertion offset will move according to their movement type. For AnchorMovementType.Default, they will move behind the inserted text. The caret will also move behind the inserted text.
public Insert ( int offset, ITextSource text ) : void
offset int The offset at which the text is inserted.
text ITextSource The new text.
return void
        private void OpenBracket(TextEditor.TextEditor editor, TextDocument document, string text)
        {
            if (text[0].IsOpenBracketChar() && editor.CaretIndex <= document.TextLength && editor.CaretIndex > 0)
            {
                var nextChar = ' ';

                if (editor.CaretIndex != document.TextLength)
                {
                    document.GetCharAt(editor.CaretIndex);
                }

                if (char.IsWhiteSpace(nextChar) || nextChar.IsCloseBracketChar())
                {
                    document.Insert(editor.CaretIndex, text[0].GetCloseBracketChar().ToString());
                }
            }
        }
        public int Comment(TextDocument textDocument, ISegment segment, int caret = -1, bool format = true)
        {
            var result = caret;

            var lines = VisualLineGeometryBuilder.GetLinesForSegmentInDocument(textDocument, segment);

            textDocument.BeginUpdate();

            foreach (var line in lines)
            {
                textDocument.Insert(line.Offset, "//");
            }

            if (format)
            {
                result = Format(textDocument, (uint)segment.Offset, (uint)segment.Length, caret);
            }

            textDocument.EndUpdate();

            return result;
        }