mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Changes for IDEA-CR-10721
This commit is contained in:
@@ -480,7 +480,7 @@ public class EnterHandler extends BaseEnterHandler {
|
||||
private int adjustLineIndent(CharSequence docChars) {
|
||||
int indentStart = CharArrayUtil.shiftBackwardUntil(docChars, myOffset - 1, "\n") + 1;
|
||||
int indentEnd = CharArrayUtil.shiftForward(docChars, indentStart, " \t");
|
||||
String newIndent = CodeStyleFacade.getInstance(getProject()).getLineIndent(myEditor, myDocument, myOffset);
|
||||
String newIndent = CodeStyleFacade.getInstance(getProject()).getLineIndent(myEditor, myOffset);
|
||||
if (newIndent == null) return myOffset;
|
||||
int delta = newIndent.length() - (indentEnd - indentStart);
|
||||
myDocument.replaceString(indentStart, indentEnd, newIndent);
|
||||
|
||||
+3
-2
@@ -59,12 +59,13 @@ public class CodeStyleFacadeImpl extends CodeStyleFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLineIndent(@NotNull Editor editor, @NotNull Document document, int offset) {
|
||||
public String getLineIndent(@NotNull Editor editor, int offset) {
|
||||
if (myProject == null) return null;
|
||||
Document document = editor.getDocument();
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
|
||||
PsiFile file = documentManager.getPsiFile(document);
|
||||
LineIndentProvider lineIndentProvider = LineIndentProviderEP.findLineIndentProvider(file);
|
||||
return lineIndentProvider != null ? lineIndentProvider.getLineIndent(myProject, editor, document, offset) : null;
|
||||
return lineIndentProvider != null ? lineIndentProvider.getLineIndent(myProject, editor, offset) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class FormatterBasedLineIndentProvider implements LineIndentProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getLineIndent(@NotNull Project project, @NotNull Editor editor, @NotNull Document document, int offset) {
|
||||
public String getLineIndent(@NotNull Project project, @NotNull Editor editor, int offset) {
|
||||
Document document = editor.getDocument();
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document);
|
||||
return CodeStyleManager.getInstance(project).getLineIndent(document, offset);
|
||||
}
|
||||
|
||||
+14
-13
@@ -17,7 +17,6 @@ package com.intellij.psi.impl.source.codeStyle;
|
||||
|
||||
import com.intellij.formatting.Indent;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
|
||||
@@ -36,10 +35,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineIndentProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getLineIndent(@NotNull Project project, @NotNull Editor editor, @NotNull Document document, int offset) {
|
||||
Indent.Type indent = getIndent(editor, document, offset);
|
||||
public String getLineIndent(@NotNull Project project, @NotNull Editor editor, int offset) {
|
||||
Indent.Type indent = getIndent(editor, offset);
|
||||
if (indent == Indent.Type.NONE) return null;
|
||||
return super.getLineIndent(project, editor, document, offset);
|
||||
return super.getLineIndent(project, editor, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,15 +52,17 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
|
||||
protected abstract boolean isSuitableForLanguage(@NotNull Language language);
|
||||
|
||||
@Nullable
|
||||
protected Indent.Type getIndent(@NotNull Editor editor, @NotNull Document document, int offset) {
|
||||
CharSequence docChars = document.getCharsSequence();
|
||||
EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
|
||||
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
|
||||
if (isWhitespace(iterator.getTokenType())) {
|
||||
if (containsLineBreaks(iterator, docChars)) {
|
||||
iterator.retreat();
|
||||
if (!iterator.atEnd()) {
|
||||
if (isEndOfCodeBlock(iterator)) return Indent.Type.NONE;
|
||||
protected Indent.Type getIndent(@NotNull Editor editor, int offset) {
|
||||
if (offset > 0) {
|
||||
CharSequence docChars = editor.getDocument().getCharsSequence();
|
||||
EditorHighlighter highlighter = ((EditorEx)editor).getHighlighter();
|
||||
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
|
||||
if (isWhitespace(iterator.getTokenType())) {
|
||||
if (containsLineBreaks(iterator, docChars)) {
|
||||
iterator.retreat();
|
||||
if (!iterator.atEnd()) {
|
||||
if (isEndOfCodeBlock(iterator)) return Indent.Type.NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.codeStyle;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -33,13 +32,12 @@ public interface LineIndentProvider {
|
||||
*
|
||||
* @param project The current project.
|
||||
* @param editor The current editor.
|
||||
* @param document The document for which the indent should be calculated.
|
||||
* @param offset The caret offset in the editor.
|
||||
* @return The indent string (possibly consisting of tabs and/or white spaces), or null if
|
||||
* LineIndentProvider can't calculate the indent (in this case no indent adjustment will be made).
|
||||
*/
|
||||
@Nullable
|
||||
String getLineIndent(@NotNull Project project, @NotNull Editor editor, @NotNull Document document, int offset);
|
||||
String getLineIndent(@NotNull Project project, @NotNull Editor editor, int offset);
|
||||
|
||||
boolean isSuitableFor(@Nullable PsiFile file);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class CodeStyleFacade {
|
||||
* @param offset the caret offset in the editor.
|
||||
* @return the indent string (containing of tabs and/or white spaces), or null if it
|
||||
* was not possible to calculate the indent.
|
||||
* @deprecated Use {@link #getLineIndent(Editor, Document, int)} instead.
|
||||
* @deprecated Use {@link #getLineIndent(Editor, int)} instead.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
@@ -55,17 +55,16 @@ public abstract class CodeStyleFacade {
|
||||
|
||||
/**
|
||||
* Calculates the indent that should be used for the line at specified offset in the specified
|
||||
* document.
|
||||
* editor.
|
||||
*
|
||||
* @param editor the editor for which the indent must be returned.
|
||||
* @param document the document for which the indent should be calculated.
|
||||
* @param offset the caret offset in the editor.
|
||||
* @return the indent string (containing of tabs and/or white spaces), or null if it
|
||||
* was not possible to calculate the indent.
|
||||
*/
|
||||
public String getLineIndent(@NotNull Editor editor, @NotNull Document document, int offset) {
|
||||
public String getLineIndent(@NotNull Editor editor, int offset) {
|
||||
//noinspection deprecation
|
||||
return getLineIndent(document, offset);
|
||||
return getLineIndent(editor.getDocument(), offset);
|
||||
}
|
||||
|
||||
public abstract int getIndentSize(FileType fileType);
|
||||
|
||||
Reference in New Issue
Block a user