mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
improved reflow paragraph action
This commit is contained in:
@@ -20,6 +20,12 @@ public class RestFillParagraphHandler extends ParagraphFillHandler {
|
||||
return element instanceof PsiComment? ".. " : "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPostfix(@NotNull PsiElement element) {
|
||||
return element.getNode().getElementType() == RestTokenTypes.COMMENT? "\n" : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailableForFile(@Nullable PsiFile psiFile) {
|
||||
return psiFile instanceof RestFile;
|
||||
@@ -35,4 +41,13 @@ public class RestFillParagraphHandler extends ParagraphFillHandler {
|
||||
return element instanceof PsiWhiteSpace ||
|
||||
element != null && element.getNode().getElementType() == RestTokenTypes.WHITESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendPostfix(@NotNull PsiElement element,
|
||||
@NotNull String text,
|
||||
@NotNull StringBuilder stringBuilder) {
|
||||
if (element.getNode().getElementType() == RestTokenTypes.COMMENT) {
|
||||
stringBuilder.append(getPostfix(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.jetbrains.python.actions;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.fillParagraph.ParagraphFillHandler;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PythonStringUtil;
|
||||
import com.jetbrains.python.psi.PyFile;
|
||||
import com.jetbrains.python.psi.PyStringLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -17,9 +19,29 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
|
||||
|
||||
@NotNull
|
||||
protected String getPrefix(@NotNull final PsiElement element) {
|
||||
final PyStringLiteralExpression stringLiteralExpression =
|
||||
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
|
||||
if (stringLiteralExpression != null) {
|
||||
final Pair<String,String> quotes =
|
||||
PythonStringUtil.getQuotes(stringLiteralExpression.getText());
|
||||
return quotes != null? quotes.getFirst()+"\n" : "\"\n";
|
||||
}
|
||||
return element instanceof PsiComment? "#" : "";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getPostfix(@NotNull PsiElement element) {
|
||||
final PyStringLiteralExpression stringLiteralExpression =
|
||||
PsiTreeUtil.getParentOfType(element, PyStringLiteralExpression.class);
|
||||
if (stringLiteralExpression != null) {
|
||||
final Pair<String,String> quotes =
|
||||
PythonStringUtil.getQuotes(stringLiteralExpression.getText());
|
||||
return quotes != null? "\n" + quotes.getSecond() : "\n\"";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailableForElement(@Nullable PsiElement element) {
|
||||
if (element != null) {
|
||||
|
||||
Reference in New Issue
Block a user