From 220ec5f408e9652b2a2b5b58ed096ef510c7679c Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Fri, 16 Feb 2018 17:48:04 +0300 Subject: [PATCH] EA-108926 - assert: TextRange. --- .../openapi/editor/impl/FoldRegionImpl.java | 19 +++------- .../openapi/editor/impl/FoldingModelImpl.java | 26 ++++---------- .../openapi/editor/impl/FoldingTest.java | 36 +++++++++++-------- 3 files changed, 31 insertions(+), 50 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java index 7941e484d6a8..a997cb37d67d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java @@ -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(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index 111b246c8ea6..9cd09e590eb6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -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() { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java index 0b6363117d5f..14b13a39a9ba 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/FoldingTest.java @@ -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 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 newRegionsInGroup = myModel.getGroupedRegions(group); + assertEquals(Arrays.asList(regions[1]), newRegionsInGroup); + } }