Folding group support. Fix CWM-172

GitOrigin-RevId: d98f91df51eacefe93ec322a851799a0802c62d7
This commit is contained in:
Alexander.Kirsanov
2020-08-18 11:02:41 +00:00
committed by intellij-monorepo-bot
parent 70a730b1c4
commit 0ef97dc482
2 changed files with 32 additions and 1 deletions
@@ -1,24 +1,53 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NonNls;
import java.util.concurrent.atomic.AtomicLong;
/**
* {@link com.intellij.openapi.editor.FoldRegion}s with same FoldingGroup instances expand and collapse together.
*
* @author peter
*/
public final class FoldingGroup {
private static final AtomicLong ourCounter = new AtomicLong();
@NonNls private final String myDebugName;
private final long myId;
private FoldingGroup(@NonNls String debugName) {
myDebugName = debugName;
myId = ourCounter.incrementAndGet();
}
public static FoldingGroup newGroup(@NonNls String debugName) {
return new FoldingGroup(debugName);
}
@ApiStatus.Internal
public long getId() {
return myId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FoldingGroup group = (FoldingGroup)o;
if (myId != group.myId) return false;
return true;
}
@Override
public int hashCode() {
return (int)(myId ^ (myId >>> 32));
}
@Override
public String toString() {
return myDebugName;
@@ -199,14 +199,16 @@ final class UpdateFoldRegionsOperation implements Runnable {
List<FoldRegion> regionsToProcess = group == null ? Collections.singletonList(region) : foldingModel.getGroupedRegions(group);
matchedInfos.clear();
boolean shouldRemove = false;
boolean isLight = true;
for (FoldRegion regionToProcess : regionsToProcess) {
if (!regionToProcess.isValid() || shouldRemoveRegion(regionToProcess, info, rangeToExpandStatusMap, infoRef)) {
shouldRemove = true;
}
isLight &= regionToProcess.getUserData(SIGNATURE) == null;
FoldingUpdate.RegionInfo regionInfo = infoRef.get();
matchedInfos.add(regionInfo);
}
if (!shouldRemove && group != null) {
if (!shouldRemove && group != null && !isLight) {
FoldingGroup requestedGroup = null;
for (FoldingUpdate.RegionInfo matchedInfo : matchedInfos) {
if (matchedInfo == null) {