From 679708e8d398d5d37ac10e225769fb04f4defdd6 Mon Sep 17 00:00:00 2001 From: Petr Kudriavtsev Date: Fri, 27 Sep 2019 16:54:25 +0300 Subject: [PATCH] Additional fix for CPP-12560: Structure view might freeze on update Used returned promise to cancel the autoscroll task instead of manually created progress indicator GitOrigin-RevId: 08fc9858e78b3118141c586e1f39901689c8346c --- .../StructureViewComponent.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java index 9ffbee7b601e..3cb9915f14c0 100644 --- a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java +++ b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java @@ -58,6 +58,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.concurrency.AsyncPromise; +import org.jetbrains.concurrency.CancellablePromise; import org.jetbrains.concurrency.Promise; import org.jetbrains.concurrency.Promises; @@ -111,7 +112,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre // read from different threads // written from EDT only @Nullable - private volatile ProgressIndicatorBase myLastAutoscrollIndicator; + private volatile CancellablePromise myLastAutoscrollPromise; public StructureViewComponent(@Nullable FileEditor editor, @@ -469,9 +470,9 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre } private void cancelScrollToSelectedElement() { - final ProgressIndicatorBase currentIndicator = myLastAutoscrollIndicator; - if (currentIndicator != null && !currentIndicator.isCanceled()) { - currentIndicator.cancel(); + final CancellablePromise lastPromise = myLastAutoscrollPromise; + if (lastPromise != null && !lastPromise.isCancelled()) { + lastPromise.cancel(); } } @@ -481,13 +482,9 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre cancelScrollToSelectedElement(); if (isDisposed()) return; - final ProgressIndicatorBase indicator = new ProgressIndicatorBase(); - myLastAutoscrollIndicator = indicator; - - ReadAction.nonBlocking(this::doFindSelectedElement) + myLastAutoscrollPromise = ReadAction.nonBlocking(this::doFindSelectedElement) .withDocumentsCommitted(myProject) - .expireWhen(this::isDisposed) - .cancelWith(indicator) + .expireWith(this) .finishOnUiThread(ModalityState.current(), this::doScrollToSelectedElement) .submit(AppExecutorUtil.getAppExecutorService()); }