mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
decouple CodeStyleFacade and CodeStyleManager from Editor
This commit is contained in:
@@ -18,7 +18,6 @@ package com.intellij.psi.codeStyle;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
@@ -191,7 +190,7 @@ public abstract class CodeStyleManager {
|
||||
* was not possible to calculate the indent.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getLineIndent(@NotNull Editor editor);
|
||||
public abstract String getLineIndent(@NotNull Document document, int offset);
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@
|
||||
package com.intellij.psi.impl.source.codeStyle;
|
||||
|
||||
import com.intellij.codeStyle.CodeStyleFacade;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -45,9 +45,9 @@ public class CodeStyleFacadeImpl extends CodeStyleFacade {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLineIndent(@NotNull final Editor editor) {
|
||||
public String getLineIndent(@NotNull final Document document, int offset) {
|
||||
if (myProject == null) return null;
|
||||
return CodeStyleManager.getInstance(myProject).getLineIndent(editor);
|
||||
return CodeStyleManager.getInstance(myProject).getLineIndent(document, offset);
|
||||
}
|
||||
|
||||
public String getLineSeparator() {
|
||||
|
||||
+2
-8
@@ -340,14 +340,8 @@ public class CodeStyleManagerImpl extends CodeStyleManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLineIndent(@NotNull Editor editor) {
|
||||
Document doc = editor.getDocument();
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
if (offset >= doc.getTextLength()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(doc);
|
||||
public String getLineIndent(@NotNull Document document, int offset) {
|
||||
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
|
||||
if (file == null) return "";
|
||||
|
||||
return getLineIndent(file, offset);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package com.intellij.codeStyle;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -38,16 +38,16 @@ public abstract class CodeStyleFacade {
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the indent that should be used for the current line in the specified
|
||||
* editor.
|
||||
* Calculates the indent that should be used for the line at specified offset in the specified
|
||||
* document.
|
||||
*
|
||||
* @param editor the editor for which the indent should be calculated.
|
||||
* @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.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract String getLineIndent(@NotNull Editor editor);
|
||||
|
||||
public abstract String getLineIndent(@NotNull Document document, int offset);
|
||||
|
||||
public abstract int getIndentSize(FileType fileType);
|
||||
|
||||
|
||||
@@ -291,7 +291,8 @@ public class EditorModificationUtil {
|
||||
final int caretOffset = editor.getCaretModel().getOffset();
|
||||
boolean atLineStart = caretOffset >= doc.getTextLength() || doc.getLineStartOffset(doc.getLineNumber(caretOffset)) == caretOffset;
|
||||
if (atLineStart && project != null) {
|
||||
String properIndent = CodeStyleFacade.getInstance(project).getLineIndent(editor);
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
String properIndent = offset >= doc.getTextLength() ? "" : CodeStyleFacade.getInstance(project).getLineIndent(doc, offset);
|
||||
if (properIndent != null) {
|
||||
int tabSize = editor.getSettings().getTabSize(project);
|
||||
for (int i = 0; i < properIndent.length(); i++) {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
package com.intellij.codeStyle;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,7 +31,7 @@ public class DefaultCodeStyleFacade extends CodeStyleFacade {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getLineIndent(@NotNull final Editor editor) {
|
||||
public String getLineIndent(@NotNull final Document document, int offset) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user