Search in sources :

Example 16 with EditorSettingsExternalizable

use of com.intellij.openapi.editor.ex.EditorSettingsExternalizable in project intellij-community by JetBrains.

the class JavaFormatterInEditorTest method testKeepWhitespacesOnEmptyLines.

public void testKeepWhitespacesOnEmptyLines() {
    CommonCodeStyleSettings.IndentOptions indentOptions = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE).getIndentOptions();
    assertNotNull(indentOptions);
    boolean keepIndents = indentOptions.KEEP_INDENTS_ON_EMPTY_LINES;
    EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    String stripSpaces = editorSettings.getStripTrailingSpaces();
    try {
        editorSettings.setStripTrailingSpaces(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE);
        indentOptions.KEEP_INDENTS_ON_EMPTY_LINES = true;
        final String initial = "<caret>package com.acme;\n" + "\n" + "class Foo {\n" + "    Integer[] foo() {\n" + "          \n" + "             \n" + "        return new Integer[]{0, 1};\n" + "    }\n" + "      \n" + "}";
        final String expected = " package com.acme;\n" + "\n" + "class Foo {\n" + "    Integer[] foo() {\n" + "        \n" + "        \n" + "        return new Integer[]{0, 1};\n" + "    }\n" + "    \n" + "}";
        configureFromFileText(getTestName(false) + ".java", initial);
        //WriteCommandAction.runWriteCommandAction(getProject(), () -> CodeStyleManager.getInstance(getProject())
        //  .reformatText(getFile(), 0, getEditor().getDocument().getTextLength()));
        Document doc = getEditor().getDocument();
        EditorTestUtil.performTypingAction(getEditor(), ' ');
        PsiDocumentManager.getInstance(getProject()).commitDocument(doc);
        FileDocumentManager.getInstance().saveAllDocuments();
        checkResultByText(expected);
    } finally {
        indentOptions.KEEP_INDENTS_ON_EMPTY_LINES = keepIndents;
        editorSettings.setStripTrailingSpaces(stripSpaces);
    }
}
Also used : CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) Document(com.intellij.openapi.editor.Document) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Example 17 with EditorSettingsExternalizable

use of com.intellij.openapi.editor.ex.EditorSettingsExternalizable in project intellij-community by JetBrains.

the class SaveAllAction method stripSpacesFromCaretLines.

private static void stripSpacesFromCaretLines(@NotNull Editor editor) {
    final EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    if (!EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(editorSettings.getStripTrailingSpaces()) && !editorSettings.isKeepTrailingSpacesOnCaretLine()) {
        Document document = editor.getDocument();
        final boolean inChangedLinesOnly = EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED.equals(editorSettings.getStripTrailingSpaces());
        TrailingSpacesStripper.strip(document, inChangedLinesOnly, false);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Example 18 with EditorSettingsExternalizable

use of com.intellij.openapi.editor.ex.EditorSettingsExternalizable in project intellij-community by JetBrains.

the class TrailingSpacesStripperTest method testOverrideEnsureNewline.

public void testOverrideEnsureNewline() throws IOException {
    EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
    settings.setEnsureNewLineAtEOF(false);
    configureFromFileText("x.txt", "XXX<caret>\nYYY");
    myVFile.putUserData(TrailingSpacesStripper.OVERRIDE_ENSURE_NEWLINE_KEY, Boolean.TRUE);
    type(' ');
    FileDocumentManager.getInstance().saveAllDocuments();
    checkResultByText("XXX <caret>\nYYY\n");
}
Also used : EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Example 19 with EditorSettingsExternalizable

use of com.intellij.openapi.editor.ex.EditorSettingsExternalizable in project intellij-community by JetBrains.

the class TrailingSpacesStripperTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
    oldSettings = settings.getState();
    settings.loadState(new EditorSettingsExternalizable.OptionSet());
    settings.setStripTrailingSpaces(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED);
    settings.setVirtualSpace(false);
}
Also used : EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Example 20 with EditorSettingsExternalizable

use of com.intellij.openapi.editor.ex.EditorSettingsExternalizable in project intellij-community by JetBrains.

the class TrailingSpacesStripperTest method testDoNotStripModifiedLines_And_EnsureBlankLineAtTheEnd_LeavesWhitespacesAtTheEndOfFileAlone.

public void testDoNotStripModifiedLines_And_EnsureBlankLineAtTheEnd_LeavesWhitespacesAtTheEndOfFileAlone() throws IOException {
    EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
    settings.setStripTrailingSpaces(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE);
    settings.setEnsureNewLineAtEOF(true);
    Document document = configureFromFileText("x.txt", "xxx <caret>\nyyy\n\t\t\t");
    // make any modification, so that Document and file content differ. Otherwise save won't be, and "on-save" actions won't be called.
    WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(0, " "));
    FileDocumentManager.getInstance().saveAllDocuments();
    checkResultByText(" xxx <caret>\nyyy\n\t\t\t\n");
}
Also used : Document(com.intellij.openapi.editor.Document) EditorSettingsExternalizable(com.intellij.openapi.editor.ex.EditorSettingsExternalizable)

Aggregations

EditorSettingsExternalizable (com.intellij.openapi.editor.ex.EditorSettingsExternalizable)31 CodeInsightSettings (com.intellij.codeInsight.CodeInsightSettings)7 UISettings (com.intellij.ide.ui.UISettings)7 RichCopySettings (com.intellij.openapi.editor.richcopy.settings.RichCopySettings)4 CommonCodeStyleSettings (com.intellij.psi.codeStyle.CommonCodeStyleSettings)4 Document (com.intellij.openapi.editor.Document)3 VcsApplicationSettings (com.intellij.openapi.vcs.VcsApplicationSettings)3 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)3 QuickDocOnMouseOverManager (com.intellij.codeInsight.documentation.QuickDocOnMouseOverManager)1 SmartBackspaceMode (com.intellij.codeInsight.editorActions.SmartBackspaceMode)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 Editor (com.intellij.openapi.editor.Editor)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1