EA-108926 - assert: TextRange.<init>

This commit is contained in:
Dmitry Batrak
2018-02-16 17:49:42 +03:00
parent 9cab5f1b12
commit 220ec5f408
3 changed files with 31 additions and 50 deletions
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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.impl;
@@ -140,6 +126,9 @@ class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion {
if (isValid()) {
alignToSurrogateBoundaries();
}
else {
myEditor.getFoldingModel().removeRegionFromGroup(this);
}
myEditor.getFoldingModel().clearCachedValues();
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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.impl;
@@ -286,11 +272,6 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu
((FoldRegionImpl)region).setExpanded(true, false);
notifyListenersOnFoldRegionStateChange(region);
final FoldingGroup group = region.getGroup();
if (group != null) {
myGroups.remove(group, region);
}
myFoldRegionsProcessed = true;
region.dispose();
}
@@ -302,6 +283,11 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu
}
myFoldRegionsProcessed = true;
myRegionTree.removeInterval(region);
removeRegionFromGroup(region);
}
void removeRegionFromGroup(@NotNull FoldRegion region) {
myGroups.remove(region.getGroup(), region);
}
public void dispose() {
@@ -1,23 +1,10 @@
/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 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.impl;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.FoldingGroup;
import com.intellij.openapi.editor.ex.FoldingListener;
import com.intellij.openapi.editor.ex.FoldingModelEx;
import com.intellij.openapi.util.Ref;
@@ -27,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -363,4 +351,22 @@ public class FoldingTest extends AbstractEditorTest {
myModel.runBatchFoldingOperation(() -> myModel.clearFoldRegions());
assertFalse(region.isValid());
}
public void testGroupIsUpdatedOnRegionDisposal() {
FoldingGroup group = FoldingGroup.newGroup("test");
FoldRegion[] regions = new FoldRegion[2];
myModel.runBatchFoldingOperation(() -> {
regions[0] = myModel.createFoldRegion(1, 2, "a", group, false);
regions[1] = myModel.createFoldRegion(3, 4, "b", group, false);
});
assertNotNull(regions[0]);
assertNotNull(regions[1]);
List<FoldRegion> regionsInGroup = myModel.getGroupedRegions(group);
assertTrue(regionsInGroup.size() == 2 && regionsInGroup.containsAll(Arrays.asList(regions)));
WriteCommandAction.runWriteCommandAction(ourProject, () -> myEditor.getDocument().deleteString(0, 3));
assertFalse(regions[0].isValid());
assertTrue(regions[1].isValid());
List<FoldRegion> newRegionsInGroup = myModel.getGroupedRegions(group);
assertEquals(Arrays.asList(regions[1]), newRegionsInGroup);
}
}