/// <remarks>
        /// Undo last operation
        /// </remarks>
        public void Undo()
        {
            // we clear all selection direct, because the redraw
            // is done per refresh at the end of the action
//			textArea.SelectionManager.SelectionCollection.Clear();
            document.UndoStack.AcceptChanges = false;
            document.Insert(offset, text);
//			document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, oldCaretPos));
            document.UndoStack.AcceptChanges = true;
        }
        void SetCommentAt(Document.Document document, string comment, SelectionManager selmgr, int y1, int y2)
        {
            firstLine = y1;
            lastLine  = y2;

            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (selmgr != null && i == y2 && line.Offset == selmgr.StartOffset + selmgr.Length)
                {
                    --lastLine;
                    continue;
                }

                string lineText = document.GetText(line.Offset, line.Length);
                document.Insert(line.Offset, comment);
            }
        }
        void InsertTabs(Document.Document document, SelectionManager selmgr, int y1, int y2)
        {
            string indentationString = GetIndentationString(document);

            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (i == y2 && i == selmgr.EndPosition.Y && selmgr.EndPosition.X == 0)
                {
                    continue;
                }

                // this bit is optional - but useful if you are using block tabbing to sort out
                // a source file with a mixture of tabs and spaces
                // string newLine = document.GetText(line.Offset,line.Length);
                // document.Replace(line.Offset,line.Length,newLine);

                document.Insert(line.Offset, indentationString);
            }
        }
 void SetCommentAt(Document.Document document, int offsetStart, int offsetEnd, string commentStart, string commentEnd)
 {
     document.Insert(offsetEnd, commentEnd);
     document.Insert(offsetStart, commentStart);
 }