Browse Source

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
pull/1/head
Matt Ward 16 years ago
parent
commit
e700f24082
  1. 4
      src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormattingStrategy.cs
  2. 14
      src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs

4
src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/PythonFormattingStrategy.cs

@ -20,6 +20,10 @@ namespace ICSharpCode.PythonBinding @@ -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();

14
src/AddIns/BackendBindings/Python/PythonBinding/Test/PythonIndentationTests.cs

@ -200,6 +200,18 @@ namespace PythonBinding.Tests.Indentation @@ -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);
}
}
}

Loading…
Cancel
Save