use of com.intellij.openapi.editor.FoldingModel in project intellij-community by JetBrains.
the class ExternalProjectPathField method collapse.
public static void collapse(@NotNull final Editor editor, @NotNull final String placeholder) {
final FoldingModel foldingModel = editor.getFoldingModel();
foldingModel.runBatchFoldingOperation(() -> {
for (FoldRegion region : foldingModel.getAllFoldRegions()) {
foldingModel.removeFoldRegion(region);
}
FoldRegion region = foldingModel.addFoldRegion(0, editor.getDocument().getTextLength(), placeholder);
if (region != null) {
region.setExpanded(false);
}
});
}
use of com.intellij.openapi.editor.FoldingModel in project intellij-community by JetBrains.
the class FoldingAnchorsOverlayStrategyTest method collapseFoldingRegion.
private void collapseFoldingRegion(int n) {
FoldingModel foldingModel = myFixture.getEditor().getFoldingModel();
final FoldRegion foldRegion = foldingModel.getAllFoldRegions()[n];
foldingModel.runBatchFoldingOperation(() -> foldRegion.setExpanded(false));
}
use of com.intellij.openapi.editor.FoldingModel in project intellij-community by JetBrains.
the class FoldingAnchorsOverlayStrategyTest method testWithEmptyLastLine.
public void testWithEmptyLastLine() {
myFixture.configureByText(FileTypes.PLAIN_TEXT, "some text\n");
final FoldingModel foldingModel = myFixture.getEditor().getFoldingModel();
foldingModel.runBatchFoldingOperation(() -> foldingModel.addFoldRegion(0, 10, "..."));
verifyAnchors(null, 0, Type.EXPANDED_TOP, 1, Type.EXPANDED_BOTTOM);
}
use of com.intellij.openapi.editor.FoldingModel in project intellij-community by JetBrains.
the class FileEditorManagerTest method testStoringCaretStateForFileWithFoldingsWithNoTabs.
public void testStoringCaretStateForFileWithFoldingsWithNoTabs() throws Exception {
int savedValue = UISettings.getInstance().getEditorTabPlacement();
UISettings.getInstance().setEditorTabPlacement(UISettings.TABS_NONE);
try {
VirtualFile file = getFile("/src/Test.java");
assertNotNull(file);
FileEditor[] editors = myManager.openFile(file, false);
assertEquals(1, editors.length);
assertTrue(editors[0] instanceof TextEditor);
Editor editor = ((TextEditor) editors[0]).getEditor();
EditorTestUtil.waitForLoading(editor);
final FoldingModel foldingModel = editor.getFoldingModel();
assertEquals(2, foldingModel.getAllFoldRegions().length);
foldingModel.runBatchFoldingOperation(() -> {
for (FoldRegion region : foldingModel.getAllFoldRegions()) {
region.setExpanded(false);
}
});
int textLength = editor.getDocument().getTextLength();
editor.getCaretModel().moveToOffset(textLength);
editor.getSelectionModel().setSelection(textLength - 1, textLength);
myManager.openFile(getFile("/src/1.txt"), false);
assertEquals(0, myManager.getEditors(file).length);
editors = myManager.openFile(file, false);
assertEquals(1, editors.length);
assertTrue(editors[0] instanceof TextEditor);
editor = ((TextEditor) editors[0]).getEditor();
EditorTestUtil.waitForLoading(editor);
assertEquals(textLength, editor.getCaretModel().getOffset());
assertEquals(textLength - 1, editor.getSelectionModel().getSelectionStart());
assertEquals(textLength, editor.getSelectionModel().getSelectionEnd());
} finally {
UISettings.getInstance().setEditorTabPlacement(savedValue);
}
}
use of com.intellij.openapi.editor.FoldingModel in project intellij-community by JetBrains.
the class AbstractRearrangerTest method doTest.
protected void doTest(@NotNull Map<String, ?> args) {
String text = (String) args.get("initial");
String expected = (String) args.get("expected");
@SuppressWarnings("unchecked") List<TextRange> ranges = (List<TextRange>) args.get("ranges");
Info info = parse(text);
if (!isEmpty(ranges) && !isEmpty(info.ranges)) {
fail("Duplicate ranges set: explicit: " + ranges + ", " + "derived: " + info.ranges + ", text:\n" + text);
}
if (isEmpty(info.ranges)) {
info.ranges = !isEmpty(ranges) ? ranges : Arrays.asList(TextRange.from(0, text.length()));
}
myFixture.configureByText(fileType, info.text);
final FoldingModel foldingModel = myFixture.getEditor().getFoldingModel();
for (final FoldingInfo foldingInfo : info.foldings) {
foldingModel.runBatchFoldingOperation(() -> {
FoldRegion region = foldingModel.addFoldRegion(foldingInfo.start, foldingInfo.end, foldingInfo.placeholder);
if (region != null)
region.setExpanded(false);
});
}
@SuppressWarnings("unchecked") List<ArrangementGroupingRule> groupingRules = (List<ArrangementGroupingRule>) args.get("groups");
if (groupingRules == null)
groupingRules = Collections.emptyList();
List<?> rules = (List<?>) args.get("rules");
List<ArrangementSectionRule> sectionRules = getSectionRules(rules);
@SuppressWarnings("unchecked") List<StdArrangementRuleAliasToken> aliases = (List<StdArrangementRuleAliasToken>) args.get("aliases");
CommonCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings().getCommonSettings(language);
final StdArrangementSettings arrangementSettings = aliases == null ? new StdArrangementSettings(groupingRules, sectionRules) : new StdArrangementExtendableSettings(groupingRules, sectionRules, aliases);
settings.setArrangementSettings(arrangementSettings);
ArrangementEngine engine = ServiceManager.getService(myFixture.getProject(), ArrangementEngine.class);
CommandProcessor.getInstance().executeCommand(getProject(), () -> engine.arrange(myFixture.getEditor(), myFixture.getFile(), info.ranges), null, null);
// Check expectation.
Info after = parse(expected);
assertEquals(after.text, myFixture.getEditor().getDocument().getText());
for (FoldingInfo it : after.foldings) {
FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(it.start);
assertNotNull("Expected to find fold region at offset " + it.start, foldRegion);
assertEquals(it.end, foldRegion.getEndOffset());
}
}
Aggregations