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
This commit is contained in:
Petr Kudriavtsev
2019-09-27 16:33:17 +00:00
committed by intellij-monorepo-bot
parent 526cec5436
commit 679708e8d3
@@ -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());
}