use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class I18nMessageGotoDeclarationHandler method getGotoDeclarationTarget.
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement element, Editor editor) {
if (!(element instanceof PsiJavaToken))
return null;
//some street magic
int i = 4;
while (element != null && i > 0) {
final ASTNode node = element.getNode();
if (node != null && node.getUserData(KEY) instanceof PropertyFoldingBuilder) {
break;
} else {
i--;
element = element.getParent();
}
}
//case: "literalAnnotatedWithPropertyKey"
if (element instanceof PsiLiteralExpression) {
return resolve(element);
}
//case: MyBundle.message("literalAnnotatedWithPropertyKey", param1, param2)
if (element instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) element;
FoldRegion foldRegion = null;
for (FoldRegion region : editor.getFoldingModel().getAllFoldRegions()) {
final PsiElement psiElement = EditorFoldingInfo.get(editor).getPsiElement(region);
if (methodCall.equals(psiElement)) {
foldRegion = region;
}
}
if (foldRegion == null || foldRegion.isExpanded())
return null;
for (PsiExpression expression : methodCall.getArgumentList().getExpressions()) {
if (expression instanceof PsiLiteralExpression && PropertyFoldingBuilder.isI18nProperty((PsiLiteralExpression) expression)) {
return resolve(expression);
}
}
}
return null;
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class ProblemPreviewEditorPresentation method updateFoldings.
private void updateFoldings() {
myEditor.getFoldingModel().runBatchFoldingOperation(() -> {
myEditor.getFoldingModel().clearFoldRegions();
myEditor.getMarkupModel().removeAllHighlighters();
for (PreviewEditorFoldingRegion region : myFoldedRegions) {
if (region.endLine - region.startLine > 1) {
FoldRegion currentRegion = FoldingModelSupport.addFolding(myEditor, region.startLine, region.endLine, false);
if (currentRegion != null) {
DiffDrawUtil.createLineSeparatorHighlighter(myEditor, myDocument.getLineStartOffset(region.startLine), myDocument.getLineEndOffset(region.endLine - 1), () -> currentRegion.isValid() && !currentRegion.isExpanded());
}
}
}
});
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class RestoreFoldArrangementCallback method afterArrangement.
@Override
public void afterArrangement(@NotNull final List<ArrangementMoveInfo> moveInfos) {
// Restore state for the PSI elements not affected by arrangement.
Project project = myEditor.getProject();
if (project != null) {
final FoldRegion[] regions = myEditor.getFoldingModel().getAllFoldRegions();
final List<FoldRegionInfo> foldRegionsInfo = new ArrayList<>();
for (FoldRegion region : regions) {
final FoldRegionInfo info = new FoldRegionInfo(region.getStartOffset(), region.getEndOffset(), region.isExpanded());
foldRegionsInfo.add(info);
}
final CodeFoldingManager foldingManager = CodeFoldingManager.getInstance(project);
foldingManager.updateFoldRegions(myEditor);
myEditor.getFoldingModel().runBatchFoldingOperation(() -> {
for (FoldRegionInfo info : foldRegionsInfo) {
final FoldRegion foldRegion = foldingManager.findFoldRegion(myEditor, info.myStart, info.myEnd);
if (foldRegion != null) {
foldRegion.setExpanded(info.myIsExpanded);
}
}
});
}
}
use of com.intellij.openapi.editor.FoldRegion 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.FoldRegion in project intellij-community by JetBrains.
the class FoldingUtil method findFoldRegionStartingAtLine.
@Nullable
public static FoldRegion findFoldRegionStartingAtLine(@NotNull Editor editor, int line) {
if (line < 0 || line >= editor.getDocument().getLineCount()) {
return null;
}
FoldRegion result = null;
FoldRegion[] regions = editor.getFoldingModel().getAllFoldRegions();
for (FoldRegion region : regions) {
if (!region.isValid()) {
continue;
}
if (region.getDocument().getLineNumber(region.getStartOffset()) == line) {
if (result != null)
return null;
result = region;
}
}
return result;
}
Aggregations