mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not use the same formatting rules inside string literals
fixed PY-9661 Fill paragraph generally bad
This commit is contained in:
@@ -2,9 +2,16 @@ package com.jetbrains.python.formatter;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.GenericLineWrapPositionStrategy;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
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.psi.StringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -44,4 +51,37 @@ public class PyLineWrapPositionStrategy extends GenericLineWrapPositionStrategy
|
||||
}
|
||||
return text.charAt(i - 2) != 'd' || text.charAt(i - 1) != 'e' || text.charAt(i) != 'f';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculateWrapPosition(@NotNull Document document,
|
||||
@Nullable Project project,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
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();
|
||||
|
||||
char c = text.charAt(wrapPosition);
|
||||
if (!StringUtil.isWhiteSpace(c) || project == null) {
|
||||
return wrapPosition;
|
||||
}
|
||||
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
if (documentManager != null) {
|
||||
final PsiFile psiFile = documentManager.getPsiFile(document);
|
||||
if (psiFile != null) {
|
||||
final PsiElement element = psiFile.findElementAt(wrapPosition);
|
||||
final StringLiteralExpression string = PsiTreeUtil.getParentOfType(element, StringLiteralExpression.class);
|
||||
|
||||
if (string != null) {
|
||||
return wrapPosition + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return wrapPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ __author__ = 'ktisha'
|
||||
def foo():
|
||||
"""
|
||||
This is my docstring. There are many like it, but this one mine. My docstring is my best friend. it is my life. I
|
||||
must master it as I must master my life. This is my docstring. There are many like it, but this one mine. My
|
||||
docstring is my best friend. it is my life. I must master it as I must master my life.
|
||||
must master it as I must master my life. This is my docstring. There are many like it, but this one mine. My
|
||||
docstring is my best friend. it is my life. I must master it as I must master my life.
|
||||
"""
|
||||
@@ -1,4 +1,4 @@
|
||||
def f():
|
||||
""" This is my docstring. There are many like it, but this one mine. My docstring is my best friend. it is my life.
|
||||
I must master it as I must master my life.
|
||||
I must master it as I must master my life.
|
||||
"""
|
||||
Reference in New Issue
Block a user