/// <summary>
        /// This function sets the indentlevel in a range of lines.
        /// </summary>
        public override void IndentLines(TextArea textArea, int begin, int end)
        {
            if (textArea.Document.TextEditorProperties.IndentStyle != IndentStyle.Smart)
            {
                base.IndentLines(textArea, begin, end);
                return;
            }
            int cursorPos       = textArea.Caret.Position.Y;
            int oldIndentLength = 0;

            if (cursorPos >= begin && cursorPos <= end)
            {
                oldIndentLength = GetIndentation(textArea, cursorPos).Length;
            }

            IndentationSettings set = new IndentationSettings();

            set.IndentString = Tab.GetIndentationString(textArea.Document);
            IndentationReformatter r   = new IndentationReformatter();
            DocumentAccessor       acc = new DocumentAccessor(textArea.Document, begin, end);

            r.Reformat(acc, set);

            if (cursorPos >= begin && cursorPos <= end)
            {
                int newIndentLength = GetIndentation(textArea, cursorPos).Length;
                if (oldIndentLength != newIndentLength)
                {
                    // fix cursor position if indentation was changed
                    int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
                    textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), cursorPos);
                }
            }
        }
		/// <summary>
		/// Define CSharp specific smart indenting for a line :)
		/// </summary>
		protected override int SmartIndentLine(TextArea textArea, int lineNr)
		{
			if (lineNr <= 0) {
				return AutoIndentLine(textArea, lineNr);
			}
			
			string oldText = textArea.Document.GetText(textArea.Document.GetLineSegment(lineNr));
			
			DocumentAccessor acc = new DocumentAccessor(textArea.Document, lineNr, lineNr);
			
			IndentationSettings set = new IndentationSettings();
			set.IndentString = Tab.GetIndentationString(textArea.Document);
			set.LeaveEmptyLines = false;
			IndentationReformatter r = new IndentationReformatter();
			
			r.Reformat(acc, set);
			
			string t = acc.Text;
			if (t.Length == 0) {
				// use AutoIndentation for new lines in comments / verbatim strings.
				return AutoIndentLine(textArea, lineNr);
			} else {
				int newIndentLength = t.Length - t.TrimStart().Length;
				int oldIndentLength = oldText.Length - oldText.TrimStart().Length;
				if (oldIndentLength != newIndentLength && lineNr == textArea.Caret.Position.Y) {
					// fix cursor position if indentation was changed
					int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
					textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), lineNr);
				}
				return newIndentLength;
			}
		}
		public override void IndentLines(ITextEditor editor, int beginLine, int endLine)
		{
			DocumentAccessor acc = new DocumentAccessor(editor.Document, beginLine, endLine);
			CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();
			indentStrategy.IndentationString = editor.Options.IndentationString;
			indentStrategy.Indent(acc, true);
		}
        public override void IndentLines(ITextEditor editor, int beginLine, int endLine)
        {
            DocumentAccessor          acc            = new DocumentAccessor(editor.Document, beginLine, endLine);
            CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();

            indentStrategy.IndentationString = GetIndentationString(editor);
            indentStrategy.Indent(acc, true);
        }
		public override void IndentLine(ITextEditor editor, IDocumentLine line)
		{
			int lineNr = line.LineNumber;
			DocumentAccessor acc = new DocumentAccessor(editor.Document, lineNr, lineNr);
			
			CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();
			indentStrategy.IndentationString = editor.Options.IndentationString;
			indentStrategy.Indent(acc, false);
			
			string t = acc.Text;
			if (t.Length == 0) {
				// use AutoIndentation for new lines in comments / verbatim strings.
				base.IndentLine(editor, line);
			}
		}
        public override void IndentLine(ITextEditor editor, IDocumentLine line)
        {
            int lineNr           = line.LineNumber;
            DocumentAccessor acc = new DocumentAccessor(editor.Document, lineNr, lineNr);

            CSharpIndentationStrategy indentStrategy = new CSharpIndentationStrategy();

            indentStrategy.IndentationString = GetIndentationString(editor);
            indentStrategy.Indent(acc, false);

            string t = acc.Text;

            if (t.Length == 0)
            {
                // use AutoIndentation for new lines in comments / verbatim strings.
                base.IndentLine(editor, line);
            }
        }
示例#7
0
        /// <summary>
        /// Define CSharp specific smart indenting for a line :)
        /// </summary>
        protected override int SmartIndentLine(TextArea textArea, int lineNr)
        {
            if (lineNr <= 0)
            {
                return(AutoIndentLine(textArea, lineNr));
            }

            string oldText = textArea.Document.GetText(textArea.Document.GetLineSegment(lineNr));

            DocumentAccessor acc = new DocumentAccessor(textArea.Document, lineNr, lineNr);

            IndentationSettings set = new IndentationSettings();

            set.IndentString    = Tab.GetIndentationString(textArea.Document);
            set.LeaveEmptyLines = false;
            IndentationReformatter r = new IndentationReformatter();

            r.Reformat(acc, set);

            if (acc.ChangedLines > 0)
            {
                textArea.Document.UndoStack.CombineLast(2);
            }

            string t = acc.Text;

            if (t.Length == 0)
            {
                // use AutoIndentation for new lines in comments / verbatim strings.
                return(AutoIndentLine(textArea, lineNr));
            }
            else
            {
                int newIndentLength = t.Length - t.TrimStart().Length;
                int oldIndentLength = oldText.Length - oldText.TrimStart().Length;
                if (oldIndentLength != newIndentLength && lineNr == textArea.Caret.Position.Y)
                {
                    // fix cursor position if indentation was changed
                    int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
                    textArea.Caret.Position = new Point(Math.Max(newX, 0), lineNr);
                }
                return(newIndentLength);
            }
        }
		/// <summary>
		/// This function sets the indentlevel in a range of lines.
		/// </summary>
		public override void IndentLines(TextArea textArea, int begin, int end)
		{
			if (textArea.Document.TextEditorProperties.IndentStyle != IndentStyle.Smart) {
				base.IndentLines(textArea, begin, end);
				return;
			}
			int cursorPos = textArea.Caret.Position.Y;
			int oldIndentLength = 0;
			
			if (cursorPos >= begin && cursorPos <= end)
				oldIndentLength = GetIndentation(textArea, cursorPos).Length;
			
			IndentationSettings set = new IndentationSettings();
			set.IndentString = Tab.GetIndentationString(textArea.Document);
			IndentationReformatter r = new IndentationReformatter();
			DocumentAccessor acc = new DocumentAccessor(textArea.Document, begin, end);
			r.Reformat(acc, set);
			
			if (cursorPos >= begin && cursorPos <= end) {
				int newIndentLength = GetIndentation(textArea, cursorPos).Length;
				if (oldIndentLength != newIndentLength) {
					// fix cursor position if indentation was changed
					int newX = textArea.Caret.Position.X - oldIndentLength + newIndentLength;
					textArea.Caret.Position = new TextLocation(Math.Max(newX, 0), cursorPos);
				}
			}
		}