Example #1
0
        private static void RunInsertBlankLinePaddingAfterEndRegionTags(Document document)
        {
            var codeItems = TestOperations.CodeModelManager.RetrieveAllCodeItems(document);
            var regions   = codeItems.OfType <CodeItemRegion>().ToList();

            _insertBlankLinePaddingLogic.InsertPaddingAfterEndRegionTags(regions);
        }
Example #2
0
        /// <summary>
        /// Inserts an #endregion tag for the specified region following the specified end point.
        /// </summary>
        /// <param name="region">The region to end.</param>
        /// <param name="endPoint">The end point.</param>
        /// <returns>The updated cursor.</returns>
        private EditPoint InsertEndRegionTag(CodeItemRegion region, EditPoint endPoint)
        {
            var cursor = endPoint.CreateEditPoint();

            // If the cursor is not preceeded only by whitespace, insert a new line.
            var firstNonWhitespaceIndex = cursor.GetLine().TakeWhile(char.IsWhiteSpace).Count();

            if (cursor.DisplayColumn > firstNonWhitespaceIndex + 1)
            {
                cursor.Insert(Environment.NewLine);
            }

            cursor.Insert("#endregion " + region.Name);

            // If the cursor is not followed only by whitespace, insert a new line.
            var lastNonWhitespaceIndex = cursor.GetLine().TrimEnd().Length;

            if (cursor.DisplayColumn < lastNonWhitespaceIndex + 1)
            {
                cursor.Insert(Environment.NewLine);
                cursor.LineUp();
                cursor.EndOfLine();
            }

            endPoint.SmartFormat(cursor);

            region.EndPoint = cursor.CreateEditPoint();

            var regionWrapper = new[] { region };

            _insertBlankLinePaddingLogic.InsertPaddingBeforeEndRegionTags(regionWrapper);
            _insertBlankLinePaddingLogic.InsertPaddingAfterEndRegionTags(regionWrapper);

            return(cursor);
        }
        /// <summary>
        /// Inserts an #endregion tag for the specified region following the specified end point.
        /// </summary>
        /// <param name="region">The region to end.</param>
        /// <param name="endPoint">The end point.</param>
        /// <returns>The updated cursor.</returns>
        public EditPoint InsertEndRegionTag(CodeItemRegion region, EditPoint endPoint)
        {
            var cursor = endPoint.CreateEditPoint();

            // If the cursor is not preceeded only by whitespace, insert a new line.
            var firstNonWhitespaceIndex = cursor.GetLine().TakeWhile(char.IsWhiteSpace).Count();

            if (cursor.DisplayColumn > firstNonWhitespaceIndex + 1)
            {
                cursor.Insert(Environment.NewLine);
            }

            cursor.Insert(RegionHelper.GetEndRegionTagText(cursor));

            if (Settings.Default.Cleaning_UpdateEndRegionDirectives &&
                RegionHelper.LanguageSupportsUpdatingEndRegionDirectives(cursor))
            {
                cursor.Insert(" " + region.Name);
            }

            // If the cursor is not followed only by whitespace, insert a new line.
            var lastNonWhitespaceIndex = cursor.GetLine().TrimEnd().Length;

            if (cursor.DisplayColumn < lastNonWhitespaceIndex + 1)
            {
                cursor.Insert(Environment.NewLine);
                cursor.LineUp();
                cursor.EndOfLine();
            }

            endPoint.SmartFormat(cursor);

            region.EndPoint = cursor.CreateEditPoint();

            var regionWrapper = new[] { region };

            _insertBlankLinePaddingLogic.InsertPaddingBeforeEndRegionTags(regionWrapper);
            _insertBlankLinePaddingLogic.InsertPaddingAfterEndRegionTags(regionWrapper);

            return(cursor);
        }