From 3ede82b128228e20ddfcec5d842ed910ed6a7fd2 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Mon, 3 Feb 2014 20:26:21 +0400 Subject: [PATCH] Fixed text range in pre-format processor. --- .../com/jetbrains/python/formatter/PyPreFormatProcessor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java index c547e3823a31..ee56016d1df9 100644 --- a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java +++ b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java @@ -59,6 +59,7 @@ public class PyPreFormatProcessor implements PreFormatProcessor { private final CodeStyleSettings mySettings; private final PyCodeStyleSettings myPyCodeStyleSettings; private TextRange myRange; + private int myDelta = 0; public PyCommentFormatter(Project project) { myProject = project; @@ -72,7 +73,7 @@ public class PyPreFormatProcessor implements PreFormatProcessor { } myRange = range; element.accept(this); - return range; + return TextRange.create(range.getStartOffset(), range.getEndOffset() + myDelta); } @Override @@ -87,6 +88,7 @@ public class PyPreFormatProcessor implements PreFormatProcessor { String newText = "# " + commentText; if (!newText.equals(text)) { + myDelta += newText.length() - text.length(); element.replace( PyElementGenerator.getInstance(myProject).createFromText(LanguageLevel.getDefault(), PsiComment.class, newText)); }