/// <summary>
        /// Inserts a #region tag for the specified region preceding the specified start point.
        /// </summary>
        /// <param name="region">The region to start.</param>
        /// <param name="startPoint">The starting point.</param>
        /// <returns>The updated cursor.</returns>
        public EditPoint InsertRegionTag(CodeItemRegion region, EditPoint startPoint)
        {
            var cursor = startPoint.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.GetRegionTagText(cursor, region.Name)}{Environment.NewLine}");

            startPoint.SmartFormat(cursor);

            region.StartPoint = cursor.CreateEditPoint();
            region.StartPoint.LineUp();
            region.StartPoint.StartOfLine();

            var regionWrapper = new[] { region };

            _insertBlankLinePaddingLogic.InsertPaddingBeforeRegionTags(regionWrapper);
            _insertBlankLinePaddingLogic.InsertPaddingAfterRegionTags(regionWrapper);

            return(cursor);
        }
Esempio n. 2
0
        private static void RunInsertBlankLinePaddingBeforeRegionTags(Document document)
        {
            var codeItems = TestOperations.CodeModelManager.RetrieveAllCodeItems(document);
            var regions   = codeItems.OfType <CodeItemRegion>().ToList();

            _insertBlankLinePaddingLogic.InsertPaddingBeforeRegionTags(regions);
        }