improved reflow paragraph action

This commit is contained in:
Ekaterina Tuzova
2013-01-21 14:01:35 +04:00
parent e025c74ea9
commit c5fa661c0f
2 changed files with 37 additions and 0 deletions
@@ -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) {