/// <summary>
        /// Create an element fold if the start and end tag are on
        /// different lines.
        /// </summary>
        private static void CreateElementFold(IDocument document, List <Fold> foldMarkers, XmlTextReader reader, XmlFoldStart foldStart)
        {
            int endLine = reader.LineNumber - 1;

            if (endLine > foldStart.Line)
            {
                int  endCol = reader.LinePosition + foldStart.Name.Length;
                Fold fold   = new Fold(document, foldStart.Line, foldStart.Column, endLine, endCol, foldStart.FoldText);
                foldMarkers.Add(fold);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the folds from position.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="column">The column.</param>
        /// <returns>The folds that include the specified position.</returns>
        public List <Fold> GetFoldsFromPosition(int line, int column)
        {
            List <Fold> foldings = new List <Fold>();

            if (_folds != null)
            {
                for (int i = 0; i < _folds.Count; ++i)
                {
                    Fold fold = _folds[i];
                    if ((fold.StartLine == line && column > fold.StartColumn && !(fold.EndLine == line && column >= fold.EndColumn)) ||
                        (fold.EndLine == line && column < fold.EndColumn && !(fold.StartLine == line && column <= fold.StartColumn)) ||
                        (line > fold.StartLine && line < fold.EndLine))
                    {
                        foldings.Add(fold);
                    }
                }
            }
            return(foldings);
        }
Ejemplo n.º 3
0
        List <Fold> GetFoldsByStartAfterColumn(int lineNumber, int column, bool forceFolded)
        {
            List <Fold> foldings = new List <Fold>();

            if (_folds != null)
            {
                Fold reference = new Fold(_document, lineNumber, column, lineNumber, column);
                int  index     = _folds.BinarySearch(reference, FoldStartComparer.Instance);

                if (index < 0)
                {
                    index = ~index;
                }

                for (; index < _folds.Count; index++)
                {
                    Fold fold = _folds[index];

                    if (fold.StartLine < lineNumber)
                    {
                        continue;
                    }
                    else if (fold.StartLine > lineNumber)
                    {
                        break;
                    }

                    if (fold.StartColumn <= column)
                    {
                        continue;
                    }

                    if (!forceFolded || fold.IsFolded)
                    {
                        foldings.Add(fold);
                    }
                }
            }
            return(foldings);
        }
        /// <summary>
        /// Creates a comment fold if the comment spans more than one line.
        /// </summary>
        /// <remarks>The text displayed when the comment is folded is the first
        /// line of the comment.</remarks>
        private static void CreateCommentFold(IDocument document, List <Fold> foldMarkers, XmlTextReader reader)
        {
            if (reader.Value != null)
            {
                string   comment = reader.Value.Replace("\r\n", "\n");
                string[] lines   = comment.Split('\n');
                if (lines.Length > 1)
                {
                    // Take off 5 chars to get the actual comment start (takes
                    // into account the <!-- chars.

                    int startCol  = reader.LinePosition - 5;
                    int startLine = reader.LineNumber - 1;

                    // Add 3 to the end col value to take into account the '-->'
                    int    endCol   = lines[lines.Length - 1].Length + startCol + 3;
                    int    endLine  = startLine + lines.Length - 1;
                    string foldText = String.Concat("<!--", lines[0], "-->");
                    Fold   fold     = new Fold(document, startLine, startCol, endLine, endCol, foldText);
                    foldMarkers.Add(fold);
                }
            }
        }