Don't wrap at the start of string literal (PY-9436).

This commit is contained in:
Dmitry Trofimov
2014-02-03 22:47:26 +04:00
parent 3ede82b128
commit e4f8eaf5ce
4 changed files with 17 additions and 1 deletions
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.text.CharArrayUtil;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.psi.StringLiteralExpression;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -75,11 +76,20 @@ public class PyLineWrapPositionStrategy extends GenericLineWrapPositionStrategy
int maxPreferredOffset,
boolean allowToBeyondMaxPreferredOffset,
boolean virtual) {
int wrapPosition =
super.calculateWrapPosition(document, project, startOffset, endOffset, maxPreferredOffset, allowToBeyondMaxPreferredOffset, virtual);
if (wrapPosition < 0) return wrapPosition;
final CharSequence text = document.getCharsSequence();
if (wrapPosition > 0) {
char charBefore = text.charAt(wrapPosition - 1);
if (charBefore == '\'' || charBefore == '"') {
//don't wrap the first char of string literal
return wrapPosition + 1;
}
}
char c = text.charAt(wrapPosition);
if (!StringUtil.isWhiteSpace(c) || project == null) {
return wrapPosition;
@@ -0,0 +1,2 @@
call_command('.'
'regressiontests_some_long_text_here_to_test_right_margin_some_long_text_here_to_test_right_margin_some_long_text_here_to_test_right_margin')
@@ -0,0 +1 @@
call_command('.regressiontests<caret>')
@@ -64,6 +64,10 @@ public class PyWrapTest extends PyTestCase {
doTest(" AND field");
}
public void testDontWrapStartOfString() { // PY-9436
doTest("_some_long_text_here_to_test_right_margin_some_long_text_here_to_test_right_margin_some_long_text_here_to_test_right_margin");
}
public void testWrapRightMargin() {
final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings();
@@ -83,7 +87,6 @@ public class PyWrapTest extends PyTestCase {
settings.RIGHT_MARGIN = oldValue;
settings.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN = oldMarginValue;
}
}
private void doTest(final String textToType) {