Beispiel #1
0
        protected override void Convert(Document.Document document, int startLine, int endLine)
        {
            List <string> lines = new List <string>();

            for (int i = startLine; i <= endLine; ++i)
            {
                LineSegment line = document.GetLineSegment(i);
                lines.Add(document.GetText(line.Offset, line.Length));
            }

            for (int i = 0; i < lines.Count - 1; ++i)
            {
                if (lines[i] == "")
                {
                    lines.RemoveAt(i);
                    --i;
                }
            }

            for (int i = 0; i < lines.Count; ++i)
            {
                LineSegment line = document.GetLineSegment(startLine + i);
                document.Replace(line.Offset, line.Length, lines[i].ToString());
            }

            // remove removed lines
            for (int i = startLine + lines.Count; i <= endLine; ++i)
            {
                LineSegment line = document.GetLineSegment(startLine + lines.Count);
                document.Remove(line.Offset, line.TotalLength);
            }
        }
Beispiel #2
0
        /// <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
//			document.SelectionCollection.Clear();

            document.UndoStack.AcceptChanges = false;
            document.Remove(offset, text.Length);
//			document.Caret.Offset = Math.Min(document.TextLength, Math.Max(0, oldCaretPos));
            document.UndoStack.AcceptChanges = true;
        }
Beispiel #3
0
        protected override void Convert(Document.Document document, int y1, int y2)
        {
            for (int i = y1; i < y2; ++i)
            {
                LineSegment line         = document.GetLineSegment(i);
                int         removeNumber = 0;

                for (int x = line.Offset; x < line.Offset + line.Length && Char.IsWhiteSpace(document.GetCharAt(x)); ++x)
                {
                    ++removeNumber;
                }

                if (removeNumber > 0)
                {
                    document.Remove(line.Offset, removeNumber);
                }
            }
        }
        void RemoveCommentAt(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);
                if (lineText.Trim().StartsWith(comment))
                {
                    document.Remove(line.Offset + lineText.IndexOf(comment), comment.Length);
                }
            }
        }
 void RemoveComment(Document.Document document, BlockCommentRegion commentRegion)
 {
     document.Remove(commentRegion.EndOffset, commentRegion.CommentEnd.Length);
     document.Remove(commentRegion.StartOffset, commentRegion.CommentStart.Length);
 }
        void RemoveTabs(Document.Document document, SelectionManager selmgr, int y1, int y2)
        {
            document.UndoStack.StartUndoGroup();
            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);
                if (i == y2 && line.Offset == selmgr.EndOffset)
                {
                    continue;
                }
                if (line.Length > 0)
                {
                    /**** TextPad Strategy:
                     * /// first convert leading whitespace to tabs (controversial! - not all editors work like this)
                     * string newLine = TextUtilities.LeadingWhiteSpaceToTabs(document.GetText(line.Offset,line.Length),document.Properties.Get("TabIndent", 4));
                     * if(newLine.Length > 0 && newLine[0] == '\t') {
                     *  document.Replace(line.Offset,line.Length,newLine.Substring(1));
                     ++redocounter;
                     * }
                     * else if(newLine.Length > 0 && newLine[0] == ' ') {
                     *  /// there were just some leading spaces but less than TabIndent of them
                     *  int leadingSpaces = 1;
                     *  for(leadingSpaces = 1; leadingSpaces < newLine.Length && newLine[leadingSpaces] == ' '; leadingSpaces++) {
                     *          /// deliberately empty
                     *  }
                     *  document.Replace(line.Offset,line.Length,newLine.Substring(leadingSpaces));
                     ++redocounter;
                     * }
                     * /// else
                     * /// there were no leading tabs or spaces on this line so do nothing
                     * /// MS Visual Studio 6 strategy:
                     ****/
                    //					string temp = document.GetText(line.Offset,line.Length);

                    if (line.Length > 0)
                    {
                        int charactersToRemove = 0;
                        if (document.GetCharAt(line.Offset) == '\t')   // first character is a tab - just remove it
                        {
                            charactersToRemove = 1;
                        }
                        else if (document.GetCharAt(line.Offset) == ' ')
                        {
                            int leadingSpaces = 1;
                            int tabIndent     = Shared.TEP.IndentationSize;
                            for (leadingSpaces = 1; leadingSpaces < line.Length && document.GetCharAt(line.Offset + leadingSpaces) == ' '; leadingSpaces++)
                            {
                                // deliberately empty
                            }
                            if (leadingSpaces >= tabIndent)
                            {
                                // just remove tabIndent
                                charactersToRemove = tabIndent;
                            }
                            else if (line.Length > leadingSpaces && document.GetCharAt(line.Offset + leadingSpaces) == '\t')
                            {
                                // remove the leading spaces and the following tab as they add up
                                // to just one tab stop
                                charactersToRemove = leadingSpaces + 1;
                            }
                            else
                            {
                                // just remove the leading spaces
                                charactersToRemove = leadingSpaces;
                            }
                        }

                        if (charactersToRemove > 0)
                        {
                            document.Remove(line.Offset, charactersToRemove);
                        }
                    }
                }
            }
            document.UndoStack.EndUndoGroup();
        }