From e700f24082e95a3aca771608fb562708231963ec Mon Sep 17 00:00:00 2001 From: Matt Ward <ward.matt@gmail.com> Date: Sat, 20 Feb 2010 14:06:32 +0000 Subject: [PATCH] Fixed argument out of range exception when indenting python code. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5519 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/PythonFormattingStrategy.cs | 4 ++++ .../PythonBinding/Test/PythonIndentationTests.cs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormattingStrategy.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormattingStrategy.cs index 55ad526f35..52ca00a018 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormattingStrategy.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormattingStrategy.cs @@ -20,6 +20,10 @@ namespace ICSharpCode.PythonBinding protected override int SmartIndentLine(TextArea textArea, int line) { + if (line == 0) { + return base.SmartIndentLine(textArea, line); + } + IDocument document = textArea.Document; LineSegment previousLine = document.GetLineSegment(line - 1); string previousLineText = document.GetText(previousLine).Trim(); diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs index 9d15beef43..866a632a5b 100644 --- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs +++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs @@ -200,6 +200,18 @@ namespace PythonBinding.Tests.Indentation "\t"; Assert.AreEqual(expectedText, textEditor.Text); - } + } + + [Test] + public void IndentingFirstLineDoesNotThrowArgumentOutOfRangeException() + { + textEditor.Text = "print 'hello'"; + + int indentResult = -1; + Assert.DoesNotThrow(delegate { indentResult = + formattingStrategy.IndentLine(textEditor.ActiveTextAreaControl.TextArea, 0); }); + + Assert.AreEqual("print 'hello'", textEditor.Text); + } } }