Exemplo n.º 1
0
        /// <summary>
        /// Get the object, which was inserted under the keyword (line, at offset, with length length),
        /// returns null, if no such keyword was inserted.
        /// </summary>
        public object this[Document.Document document, LineSegment line, int offset, int length]
        {
            get
            {
                if (length == 0)
                {
                    return(null);
                }
                Node next = root;

                int wordOffset = line.Offset + offset;
                if (casesensitive)
                {
                    for (int i = 0; i < length; ++i)
                    {
                        int index = ((int)document.GetCharAt(wordOffset + i)) % 256;
                        next = next[index];

                        if (next == null)
                        {
                            return(null);
                        }

                        if (next.color != null && RegionMatches(document, wordOffset, length, next.word))
                        {
                            return(next.color);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < length; ++i)
                    {
                        int index = ((int)Char.ToUpper(document.GetCharAt(wordOffset + i))) % 256;

                        next = next[index];

                        if (next == null)
                        {
                            return(null);
                        }

                        if (next.color != null && RegionMatches(document, casesensitive, wordOffset, length, next.word))
                        {
                            return(next.color);
                        }
                    }
                }
                return(null);
            }
        }
Exemplo n.º 2
0
        public static bool RegionMatches(Document.Document document, int offset, int length, char[] word)
        {
            if (length != word.Length || document.TextLength < offset + length)
            {
                return(false);
            }

            for (int i = 0; i < length; ++i)
            {
                if (document.GetCharAt(offset + i) != word[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public static bool RegionMatches(Document.Document document, bool casesensitive, int offset, int length, char[] word)
        {
            if (casesensitive)
            {
                return(RegionMatches(document, offset, length, word));
            }

            if (length != word.Length || document.TextLength < offset + length)
            {
                return(false);
            }

            for (int i = 0; i < length; ++i)
            {
                if (Char.ToUpper(document.GetCharAt(offset + i)) != Char.ToUpper(word[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
        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();
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
0
        protected override void Convert(Document.Document document, int y1, int y2)
        {
            for (int i = y2; i >= y1; --i)
            {
                LineSegment line = document.GetLineSegment(i);

                if (line.Length > 0)
                {
                    // count how many whitespace characters there are at the start
                    int whiteSpace;

                    for (whiteSpace = 0; whiteSpace < line.Length && char.IsWhiteSpace(document.GetCharAt(line.Offset + whiteSpace)); whiteSpace++)
                    {
                        // deliberately empty
                    }

                    if (whiteSpace > 0)
                    {
                        string newLine   = document.GetText(line.Offset, whiteSpace);
                        string newPrefix = newLine.Replace("\t", new string(' ', Shared.TEP.TabIndent));
                        document.Replace(line.Offset, whiteSpace, newPrefix);
                    }
                }
            }
        }