Search in sources :

Example 1 with CodeStyleFacade

use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.

the class FileDocumentManagerImpl method getLineSeparator.

@Override
@NotNull
public String getLineSeparator(@Nullable VirtualFile file, @Nullable Project project) {
    String lineSeparator = file == null ? null : LoadTextUtil.getDetectedLineSeparator(file);
    if (lineSeparator == null) {
        CodeStyleFacade settingsManager = project == null ? CodeStyleFacade.getInstance() : CodeStyleFacade.getInstance(project);
        lineSeparator = settingsManager.getLineSeparator();
    }
    return lineSeparator;
}
Also used : CodeStyleFacade(com.intellij.codeStyle.CodeStyleFacade) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CodeStyleFacade

use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.

the class SmartIndentingBackspaceHandler method doBeforeCharDeleted.

@Override
protected void doBeforeCharDeleted(char c, PsiFile file, Editor editor) {
    Project project = file.getProject();
    Document document = editor.getDocument();
    CharSequence charSequence = document.getImmutableCharSequence();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    LogicalPosition pos = caretModel.getLogicalPosition();
    int lineStartOffset = document.getLineStartOffset(pos.line);
    int beforeWhitespaceOffset = CharArrayUtil.shiftBackward(charSequence, caretOffset - 1, " \t") + 1;
    if (beforeWhitespaceOffset != lineStartOffset) {
        myReplacement = null;
        return;
    }
    PsiDocumentManager.getInstance(project).commitDocument(document);
    CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
    myReplacement = codeStyleFacade.getLineIndent(document, lineStartOffset);
    if (myReplacement == null) {
        return;
    }
    int tabSize = codeStyleFacade.getTabSize(file.getFileType());
    int targetColumn = getWidth(myReplacement, tabSize);
    int endOffset = CharArrayUtil.shiftForward(charSequence, caretOffset, " \t");
    LogicalPosition logicalPosition = caretOffset < endOffset ? editor.offsetToLogicalPosition(endOffset) : pos;
    int currentColumn = logicalPosition.column;
    if (currentColumn > targetColumn) {
        myStartOffset = lineStartOffset;
    } else if (logicalPosition.line == 0) {
        myStartOffset = 0;
        myReplacement = "";
    } else {
        int prevLineEndOffset = document.getLineEndOffset(logicalPosition.line - 1);
        myStartOffset = CharArrayUtil.shiftBackward(charSequence, prevLineEndOffset - 1, " \t") + 1;
        if (myStartOffset != document.getLineStartOffset(logicalPosition.line - 1)) {
            int spacing = CodeStyleManager.getInstance(project).getSpacing(file, endOffset);
            myReplacement = StringUtil.repeatSymbol(' ', Math.max(0, spacing));
        }
    }
}
Also used : CodeStyleFacade(com.intellij.codeStyle.CodeStyleFacade) Project(com.intellij.openapi.project.Project) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) CaretModel(com.intellij.openapi.editor.CaretModel) Document(com.intellij.openapi.editor.Document)

Example 3 with CodeStyleFacade

use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.

the class DiffUtil method setEditorCodeStyle.

public static void setEditorCodeStyle(@Nullable Project project, @NotNull EditorEx editor, @Nullable FileType fileType) {
    if (project != null && fileType != null) {
        CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
        editor.getSettings().setTabSize(codeStyleFacade.getTabSize(fileType));
        editor.getSettings().setUseTabCharacter(codeStyleFacade.useTabCharacter(fileType));
    }
    editor.getSettings().setCaretRowShown(false);
    editor.reinitSettings();
}
Also used : CodeStyleFacade(com.intellij.codeStyle.CodeStyleFacade)

Example 4 with CodeStyleFacade

use of com.intellij.codeStyle.CodeStyleFacade in project intellij-community by JetBrains.

the class DiffUtil method createEditor.

public static EditorEx createEditor(Document document, Project project, boolean isViewer, @Nullable FileType fileType) {
    EditorFactory factory = EditorFactory.getInstance();
    EditorEx editor = (EditorEx) (isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));
    editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
    editor.getGutterComponentEx().revalidateMarkup();
    if (fileType != null && project != null && !project.isDisposed()) {
        CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
        editor.getSettings().setTabSize(codeStyleFacade.getTabSize(fileType));
        editor.getSettings().setUseTabCharacter(codeStyleFacade.useTabCharacter(fileType));
    }
    return editor;
}
Also used : CodeStyleFacade(com.intellij.codeStyle.CodeStyleFacade) EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Aggregations

CodeStyleFacade (com.intellij.codeStyle.CodeStyleFacade)4 CaretModel (com.intellij.openapi.editor.CaretModel)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 Project (com.intellij.openapi.project.Project)1 NotNull (org.jetbrains.annotations.NotNull)1