mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Don't wrap at the start of string literal (PY-9436).
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user