From 591634c8c5ff09ec33e39d15654ae9cc5f9680e6 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 9 Mar 2018 18:23:38 +0100 Subject: [PATCH] Notify folding listener about folding region removal --- .../openapi/editor/ex/FoldingListener.java | 30 ++++++++----------- .../openapi/editor/impl/FoldingModelImpl.java | 8 +++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/FoldingListener.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/FoldingListener.java index 5ca4ee4c1ab6..5d637442ed83 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/FoldingListener.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/FoldingListener.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2010 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.ex; import com.intellij.openapi.editor.FoldRegion; @@ -27,17 +13,25 @@ import org.jetbrains.annotations.NotNull; public interface FoldingListener { /** - * Informs that {@code 'collapsed'} state of given fold region is just changed. + * Informs that {@code 'collapsed'} state of given fold region is just changed, or that the given fold region has just been created. *

* Note: listener should delay fold region state processing until {@link #onFoldProcessingEnd()} is called. * I.e. folding model may return inconsistent data between current moment and {@link #onFoldProcessingEnd()}. * * @param region fold region that is just collapsed or expanded */ - void onFoldRegionStateChange(@NotNull FoldRegion region); + default void onFoldRegionStateChange(@NotNull FoldRegion region) { + } + + /** + * Informs that the given fold region is about to be removed. + */ + default void beforeFoldRegionRemoved(@NotNull FoldRegion region) { + } /** * Informs that fold processing is done. */ - void onFoldProcessingEnd(); + default void onFoldProcessingEnd() { + } } 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 9cd09e590eb6..7040c5b6cb9d 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 @@ -271,6 +271,7 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu ((FoldRegionImpl)region).setExpanded(true, false); notifyListenersOnFoldRegionStateChange(region); + notifyListenersOnFoldRegionRemove(region); myFoldRegionsProcessed = true; region.dispose(); @@ -304,6 +305,7 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu FoldRegion[] regions = getAllFoldRegions(); for (FoldRegion region : regions) { if (!region.isExpanded()) notifyListenersOnFoldRegionStateChange(region); + notifyListenersOnFoldRegionRemove(region); region.dispose(); } doClearFoldRegions(); @@ -591,6 +593,12 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedInternalDocu } } + private void notifyListenersOnFoldRegionRemove(@NotNull FoldRegion foldRegion) { + for (FoldingListener listener : myListeners) { + listener.beforeFoldRegionRemoved(foldRegion); + } + } + @NotNull @Override public String dumpState() {