diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/FileAnnotation.java b/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/FileAnnotation.java index 36bace83a5c4..4a0ef05869ce 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/FileAnnotation.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/FileAnnotation.java @@ -24,6 +24,7 @@ import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vcs.vfs.VcsVirtualFile; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Consumer; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NotNull; @@ -41,7 +42,7 @@ public abstract class FileAnnotation { @NotNull private final Project myProject; private Runnable myCloser; - private Runnable myReloader; + private Consumer myReloader; protected FileAnnotation(@NotNull Project project) { myProject = project; @@ -180,10 +181,14 @@ public abstract class FileAnnotation { } /** - * Notify that annotation information has changed, and UI should be updated. + * Notify that annotation information has changed, and should be updated. + * If `this` is visible, hide it and show new one instead. + * If `this` is not visible, do nothing. + * + * @param newFileAnnotation annotations to be shown */ - public final void reload() { - if (myReloader != null) myReloader.run(); + public final void reload(@NotNull FileAnnotation newFileAnnotation) { + if (myReloader != null) myReloader.consume(newFileAnnotation); } /** @@ -196,7 +201,7 @@ public abstract class FileAnnotation { /** * @see #reload() */ - public final void setReloader(@Nullable Runnable reloader) { + public final void setReloader(@Nullable Consumer reloader) { myReloader = reloader; } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java index dee74d044254..3c4a87319999 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AnnotateToggleAction.java @@ -25,6 +25,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.localVcs.UpToDateLineNumberProvider; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Couple; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.ProjectLevelVcsManager; @@ -101,9 +102,10 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware { }); }); - fileAnnotation.setReloader(() -> { + fileAnnotation.setReloader(newFileAnnotation -> { if (editor.getGutter().isAnnotationsShown()) { - doAnnotate(editor, project, currentFile, fileAnnotation, vcs, upToDateLineNumberProvider); + assert Comparing.equal(currentFile, newFileAnnotation.getFile()); + doAnnotate(editor, project, currentFile, newFileAnnotation, vcs, upToDateLineNumberProvider); } }); diff --git a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java index 6ee4137e0a5e..2e1f073ec883 100644 --- a/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java +++ b/plugins/git4idea/src/git4idea/annotate/GitAnnotationProvider.java @@ -197,8 +197,9 @@ public class GitAnnotationProvider implements AnnotationProviderEx { (revisions) -> { if (revisions == null) return; ApplicationManager.getApplication().invokeLater(() -> { + GitFileAnnotation newFileAnnotation = new GitFileAnnotation(fileAnnotation); fileAnnotation.setRevisions(revisions); - fileAnnotation.reload(); + fileAnnotation.reload(newFileAnnotation); }); }, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS diff --git a/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java b/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java index 9bbcacaa6d2e..47801a823789 100644 --- a/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java +++ b/plugins/git4idea/src/git4idea/annotate/GitFileAnnotation.java @@ -87,6 +87,10 @@ public class GitFileAnnotation extends FileAnnotation { myLines = lines; } + public GitFileAnnotation(@NotNull GitFileAnnotation annotation) { + this(annotation.getProject(), annotation.getFile(), annotation.getCurrentRevision(), annotation.getLines()); + } + @Override public void dispose() { }