mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
@@ -49,6 +50,7 @@ public class FoldingUpdate {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.folding.impl.FoldingUpdate");
|
||||
|
||||
private static final Key<ParameterizedCachedValue<Runnable, Pair<Boolean,Boolean>>> CODE_FOLDING_KEY = Key.create("code folding");
|
||||
private static final Key<String> CODE_FOLDING_FILE_EXTENSION_KEY = Key.create("code folding file extension");
|
||||
|
||||
private static final Comparator<PsiElement> COMPARE_BY_OFFSET = new Comparator<PsiElement>() {
|
||||
public int compare(PsiElement element, PsiElement element1) {
|
||||
@@ -67,13 +69,30 @@ public class FoldingUpdate {
|
||||
final Project project = file.getProject();
|
||||
final Document document = editor.getDocument();
|
||||
LOG.assertTrue(!PsiDocumentManager.getInstance(project).isUncommited(document));
|
||||
|
||||
String currentFileExtension = null;
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
currentFileExtension = virtualFile.getExtension();
|
||||
}
|
||||
|
||||
ParameterizedCachedValue<Runnable, Pair<Boolean,Boolean>> value = editor.getUserData(CODE_FOLDING_KEY);
|
||||
if (value != null) {
|
||||
// There was a problem that old fold regions have been cached on file extension change (e.g. *.java -> *.groovy).
|
||||
// We want to drop them in such circumstances.
|
||||
final String oldExtension = editor.getUserData(CODE_FOLDING_FILE_EXTENSION_KEY);
|
||||
if (oldExtension == null ? currentFileExtension != null : !oldExtension.equals(currentFileExtension)) {
|
||||
value = null;
|
||||
editor.putUserData(CODE_FOLDING_KEY, null);
|
||||
}
|
||||
}
|
||||
editor.putUserData(CODE_FOLDING_FILE_EXTENSION_KEY, currentFileExtension);
|
||||
|
||||
if (value != null && value.hasUpToDateValue() && !applyDefaultState) return null;
|
||||
if (quick) return getUpdateResult(file, document, quick, project, editor, applyDefaultState).getValue();
|
||||
|
||||
return CachedValuesManager.getManager(project).getParameterizedCachedValue(editor, CODE_FOLDING_KEY,
|
||||
new ParameterizedCachedValueProvider<Runnable, Pair<Boolean,Boolean>>() {
|
||||
return CachedValuesManager.getManager(project).getParameterizedCachedValue(
|
||||
editor, CODE_FOLDING_KEY, new ParameterizedCachedValueProvider<Runnable, Pair<Boolean, Boolean>>() {
|
||||
public CachedValueProvider.Result<Runnable> compute(Pair<Boolean,Boolean> param) {
|
||||
Document document = editor.getDocument();
|
||||
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
|
||||
|
||||
Reference in New Issue
Block a user