コード例 #1
0
        /// <summary>
        /// Indents each line by specified number of spaces.
        /// </summary>
        public static string IndentLinesBy(this string lines, int leadingSpaces, IndentOptions options)
        {
            if (lines == null)
            {
                throw new ArgumentNullException("lines");
            }

            return(lines.SplitLines().IndentBy(leadingSpaces, options).JoinLines());
        }
コード例 #2
0
        /// <summary>
        /// Indents each line by specified number of spaces.
        /// </summary>
        public static IEnumerable<string> IndentBy(this IEnumerable<string> lines, int leadingSpaces, IndentOptions options)
        {
            if (lines == null) throw new ArgumentNullException("lines");

            bool firstLine = true;
            foreach (var line in lines)
            {
                if (firstLine && options.HasAnyFlag(options))
                {
                    yield return line;
                }

                yield return new string(' ', leadingSpaces) + line;
            }
        }
コード例 #3
0
        /// <summary>
        /// Indents each line by specified number of spaces.
        /// </summary>
        public static string IndentLinesBy(this string lines, int leadingSpaces, IndentOptions options)
        {
            if (lines == null) throw new ArgumentNullException("lines");

            return lines.SplitLines().IndentBy(leadingSpaces, options).JoinLines();
        }
コード例 #4
0
        private void _OnTextDocumentBeforeKeyPress(string keypress, TextSelection selection, bool inStatementCompletion, ref bool cancelKeypress)
        {
            const char BACKSPACE_CHAR_ASCII = (char)8;
            if (keypress != BACKSPACE_CHAR_ASCII.ToString(CultureInfo.InvariantCulture))
                return;

            var textDocument = (TextDocument)_applicationObject.ActiveDocument.Object("TextDocument");
            if (textDocument == null)
                return;

            IndentOptions indentOptions;
            if (_languageIndentOptions.ContainsKey(textDocument.Language) == false)
            {
                Properties properties = _applicationObject.get_Properties("TextEditor", textDocument.Language);
                indentOptions = new IndentOptions
                                    {
                                        InsertTabs = bool.Parse(properties.Item("InsertTabs").Value.ToString()),
                                        IndentSize = int.Parse(properties.Item("IndentSize").Value.ToString())
                                    };

                _languageIndentOptions.Add(textDocument.Language, indentOptions);
            }
            else
                indentOptions = _languageIndentOptions[textDocument.Language];

            // if tabs are used for indentation lets not do anything
            if (indentOptions.InsertTabs)
                return;

            var lineStartPoint = selection.ActivePoint.CreateEditPoint();
            lineStartPoint.StartOfLine();

            var activeEditPoint = selection.ActivePoint.CreateEditPoint();
            string currentLine = activeEditPoint.GetText(lineStartPoint);

            if (currentLine.Length == 0)
                return;

            // if the current line full of white space chars and multiple of indent size then left indent by deleting
            // indent amount of white space character
            const char WHITESPACE_CHAR = ' ';
            if (IsLineFullOf(currentLine, WHITESPACE_CHAR) && (currentLine.Length % indentOptions.IndentSize) == 0)
            {
                activeEditPoint.CharLeft(indentOptions.IndentSize);
                activeEditPoint.Delete(indentOptions.IndentSize);
                cancelKeypress = true;
            }
        }
コード例 #5
0
        /// <summary>
        /// Indents each line by specified number of spaces.
        /// </summary>
        public static IEnumerable <string> IndentBy(this IEnumerable <string> lines, int leadingSpaces, IndentOptions options)
        {
            if (lines == null)
            {
                throw new ArgumentNullException("lines");
            }

            bool firstLine = true;

            foreach (var line in lines)
            {
                if (firstLine && options.HasAnyFlag(options))
                {
                    yield return(line);
                }

                yield return(new string(' ', leadingSpaces) + line);
            }
        }