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);
}
}
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);
}
}
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");
}
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);
}
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");
}
Aggregations