IDEA-291970 diff: mark places with explicit selection
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Sun, 22 May 2022 17:30:49 +0000 (19:30 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 23 May 2022 11:30:06 +0000 (11:30 +0000)
GitOrigin-RevId: af26ea1b5ae54de751e941d5cca8779eb52c4044

platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeViewDiffRequestProcessor.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/VcsChangesSelectionRule.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/diff/ShowDiffFromLocalChangesActionProvider.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowser.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsTreeModelData.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/RepositoryBrowser.kt
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/history/CompareRevisionsFromFileHistoryActionProvider.java
plugins/git4idea/src/git4idea/index/ui/GitStageTree.kt

index c939e6b1f16d7fdb763496345eb9608e7296bf3b..013ac4b4849c2118fa7f67000c4c8285d6bcac40 100644 (file)
@@ -58,6 +58,7 @@ public abstract class ChangeViewDiffRequestProcessor extends CacheDiffRequestPro
     Wrapper change = getCurrentChange();
     List<Wrapper> changes = (selectedOnly ? getSelectedChanges() : getAllChanges()).collect(Collectors.toList());
     return ListSelection.create(changes, change)
     Wrapper change = getCurrentChange();
     List<Wrapper> changes = (selectedOnly ? getSelectedChanges() : getAllChanges()).collect(Collectors.toList());
     return ListSelection.create(changes, change)
+      .withExplicitSelection(selectedOnly)
       .map(wrapper -> wrapper.createProducer(project));
   }
 
       .map(wrapper -> wrapper.createProducer(project));
   }
 
index 4319123267c1bd9ad483f1b04163c05e6b455987..9b89bda7bd5bc207936b9a85f82dd028455840bc 100644 (file)
@@ -38,7 +38,8 @@ public class VcsChangesSelectionRule implements GetDataRule {
   public ListSelection<Change> getChangesSelection(@NotNull DataProvider dataProvider) {
     Change[] selectedChanges = VcsDataKeys.SELECTED_CHANGES.getData(dataProvider);
     if (selectedChanges != null) {
   public ListSelection<Change> getChangesSelection(@NotNull DataProvider dataProvider) {
     Change[] selectedChanges = VcsDataKeys.SELECTED_CHANGES.getData(dataProvider);
     if (selectedChanges != null) {
-      return ListSelection.createAt(Arrays.asList(selectedChanges), 0);
+      return ListSelection.createAt(Arrays.asList(selectedChanges), 0)
+        .withExplicitSelection(true);
     }
 
     Change[] changes = VcsDataKeys.CHANGES.getData(dataProvider);
     }
 
     Change[] changes = VcsDataKeys.CHANGES.getData(dataProvider);
index 22714c8d2538da5708fd64c6aad066efd7040be0..86d57f01d804fda1ea962d7565ae165d12dc3bf2 100644 (file)
@@ -146,9 +146,9 @@ public class ShowDiffFromLocalChangesActionProvider implements AnActionExtension
 
   @NotNull
   public static ListSelection<Producer> collectRequestProducers(@NotNull Project project,
 
   @NotNull
   public static ListSelection<Producer> collectRequestProducers(@NotNull Project project,
-                                                                 @NotNull List<? extends Change> changes,
-                                                                 @NotNull List<? extends FilePath> unversioned,
-                                                                 @NotNull ChangesListView changesView) {
+                                                                @NotNull List<? extends Change> changes,
+                                                                @NotNull List<? extends FilePath> unversioned,
+                                                                @NotNull ChangesListView changesView) {
     if (changes.size() == 1 && unversioned.isEmpty()) { // show all changes from this changelist
       Change selectedChange = changes.get(0);
       List<Change> selectedChanges = changesView.getAllChangesFromSameChangelist(selectedChange);
     if (changes.size() == 1 && unversioned.isEmpty()) { // show all changes from this changelist
       Change selectedChange = changes.get(0);
       List<Change> selectedChanges = changesView.getAllChangesFromSameChangelist(selectedChange);
@@ -171,7 +171,8 @@ public class ShowDiffFromLocalChangesActionProvider implements AnActionExtension
 
     ListSelection<Producer> changeProducers = createChangeProducers(project, changes, 0);
     ListSelection<Producer> unversionedProducers = createUnversionedProducers(project, unversioned, 0);
 
     ListSelection<Producer> changeProducers = createChangeProducers(project, changes, 0);
     ListSelection<Producer> unversionedProducers = createUnversionedProducers(project, unversioned, 0);
-    return ListSelection.createAt(ContainerUtil.concat(changeProducers.getList(), unversionedProducers.getList()), 0);
+    return ListSelection.createAt(ContainerUtil.concat(changeProducers.getList(), unversionedProducers.getList()), 0)
+      .asExplicitSelection();
   }
 
   private static ListSelection<Producer> createChangeProducers(@NotNull Project project,
   }
 
   private static ListSelection<Producer> createChangeProducers(@NotNull Project project,
index f87da526e35f3b3424ff16838a01a09bc6fc139e..da008397b8cb0d46e47c2588068d199d9c57563f 100644 (file)
@@ -488,7 +488,7 @@ public class ShelvedChangesViewManager implements Disposable {
         }
       }
     }
         }
       }
     }
-    return wrappers;
+    return wrappers.asExplicitSelection();
   }
 
   @NotNull
   }
 
   @NotNull
index 3ef3b4b6a4682142e44e8534f78baf1971e79bdd..4baa8d466526cb13ad81bb5db75539dd438256d1 100644 (file)
@@ -80,7 +80,7 @@ public class ChangesBrowser extends JPanel implements DataProvider, TypeSafeData
       MyUseCase.LOCAL_CHANGES.equals(useCase) ? RemoteRevisionsCache.getInstance(myProject).getChangesNodeDecorator() : null;
 
     myViewer = new ChangesTreeList<>(myProject, changes, capableOfExcludingChanges,
       MyUseCase.LOCAL_CHANGES.equals(useCase) ? RemoteRevisionsCache.getInstance(myProject).getChangesNodeDecorator() : null;
 
     myViewer = new ChangesTreeList<>(myProject, changes, capableOfExcludingChanges,
-                                                         highlightProblems, inclusionListener, decorator) {
+                                     highlightProblems, inclusionListener, decorator) {
       @Override
       protected DefaultTreeModel buildTreeModel(final List<Change> changes11, ChangeNodeDecorator changeNodeDecorator) {
         return ChangesBrowser.this.buildTreeModel(changes11, changeNodeDecorator, isShowFlatten());
       @Override
       protected DefaultTreeModel buildTreeModel(final List<Change> changes11, ChangeNodeDecorator changeNodeDecorator) {
         return ChangesBrowser.this.buildTreeModel(changes11, changeNodeDecorator, isShowFlatten());
@@ -244,11 +244,13 @@ public class ChangesBrowser extends JPanel implements DataProvider, TypeSafeData
   private ListSelection<Change> getChangesSelection() {
     final Change leadSelection = myViewer.getLeadSelection();
     List<Change> changes = getSelectedChanges();
   private ListSelection<Change> getChangesSelection() {
     final Change leadSelection = myViewer.getLeadSelection();
     List<Change> changes = getSelectedChanges();
+    boolean explicitSelection = true;
 
     if (changes.size() < 2) {
       List<Change> allChanges = myViewer.getChanges();
       if (allChanges.size() > 1 || changes.isEmpty()) {
         changes = allChanges;
 
     if (changes.size() < 2) {
       List<Change> allChanges = myViewer.getChanges();
       if (allChanges.size() > 1 || changes.isEmpty()) {
         changes = allChanges;
+        explicitSelection = false;
       }
     }
 
       }
     }
 
@@ -256,7 +258,8 @@ public class ChangesBrowser extends JPanel implements DataProvider, TypeSafeData
       return ListSelection.createSingleton(leadSelection);
     }
 
       return ListSelection.createSingleton(leadSelection);
     }
 
-    return ListSelection.create(changes, leadSelection);
+    return ListSelection.create(changes, leadSelection)
+      .withExplicitSelection(explicitSelection);
   }
 
   protected void afterDiffRefresh() {
   }
 
   protected void afterDiffRefresh() {
index 13526a15c0e61000026bb719ea72858f4281b0a2..728dd5b0383c9407f588b26bf3c01805a0376fe1 100644 (file)
@@ -272,7 +272,8 @@ public abstract class VcsTreeModelData {
   public static ListSelection<Object> getListSelectionOrAll(@NotNull JTree tree) {
     List<Object> entries = selected(tree).userObjects();
     if (entries.size() > 1) {
   public static ListSelection<Object> getListSelectionOrAll(@NotNull JTree tree) {
     List<Object> entries = selected(tree).userObjects();
     if (entries.size() > 1) {
-      return ListSelection.createAt(entries, 0);
+      return ListSelection.createAt(entries, 0)
+        .asExplicitSelection();
     }
 
     ChangesBrowserNode<?> selected = selected(tree).nodesStream().findFirst().orElse(null);
     }
 
     ChangesBrowserNode<?> selected = selected(tree).nodesStream().findFirst().orElse(null);
@@ -286,7 +287,8 @@ public abstract class VcsTreeModelData {
     }
 
     if (allEntries.size() <= entries.size()) {
     }
 
     if (allEntries.size() <= entries.size()) {
-      return ListSelection.createAt(entries, 0).asExplicitSelection();
+      return ListSelection.createAt(entries, 0)
+        .asExplicitSelection();
     }
     else {
       int index = selected != null ? ContainerUtil.indexOfIdentity(allEntries, selected.getUserObject()) : 0;
     }
     else {
       int index = selected != null ? ContainerUtil.indexOfIdentity(allEntries, selected.getUserObject()) : 0;
index 817648c57e3d542cc18d423ac3021b3e97ddc4cc..84457b51ef7834815ffc64c71de783887192dea8 100644 (file)
@@ -4,6 +4,7 @@ package com.intellij.openapi.vcs.impl
 import com.intellij.icons.AllIcons
 import com.intellij.ide.impl.ContentManagerWatcher
 import com.intellij.openapi.Disposable
 import com.intellij.icons.AllIcons
 import com.intellij.ide.impl.ContentManagerWatcher
 import com.intellij.openapi.Disposable
+import com.intellij.openapi.ListSelection
 import com.intellij.openapi.actionSystem.*
 import com.intellij.openapi.fileChooser.FileChooserDescriptor
 import com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl
 import com.intellij.openapi.actionSystem.*
 import com.intellij.openapi.fileChooser.FileChooserDescriptor
 import com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl
@@ -180,8 +181,9 @@ class DiffRepoWithLocalAction : AnActionExtensionProvider {
 
   override fun actionPerformed(e: AnActionEvent) {
     val repoBrowser = e.getData(REPOSITORY_BROWSER_DATA_KEY) ?: return
 
   override fun actionPerformed(e: AnActionEvent) {
     val repoBrowser = e.getData(REPOSITORY_BROWSER_DATA_KEY) ?: return
-    val changes = repoBrowser.getSelectionAsChanges()
-    ShowDiffAction.showDiffForChange(repoBrowser.project, changes)
+    val selection = ListSelection.createAt(repoBrowser.getSelectionAsChanges(), 0)
+      .asExplicitSelection()
+    ShowDiffAction.showDiffForChange(repoBrowser.project, selection)
   }
 }
 
   }
 }
 
index abaeaa63fdaae5e1bd3e1ffffd5f8741654a36e1..55a4016c6fbed5037ae7377df6158933b98eeb3b 100644 (file)
@@ -1,6 +1,7 @@
 // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
 package com.intellij.vcs.log.ui.actions.history;
 
 // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
 package com.intellij.vcs.log.ui.actions.history;
 
+import com.intellij.openapi.ListSelection;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.AnActionExtensionProvider;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.AnActionExtensionProvider;
 import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -58,7 +59,9 @@ abstract public class CompareRevisionsFromFileHistoryActionProvider implements A
     Change[] changes = e.getData(VcsDataKeys.SELECTED_CHANGES);
     if (changes == null || changes.length != 1 || changes[0] == null) return;
 
     Change[] changes = e.getData(VcsDataKeys.SELECTED_CHANGES);
     if (changes == null || changes.length != 1 || changes[0] == null) return;
 
-    ShowDiffAction.showDiffForChange(project, Arrays.asList(changes));
+    ListSelection<Change> selection = ListSelection.createAt(Arrays.asList(changes), 0)
+      .asExplicitSelection();
+    ShowDiffAction.showDiffForChange(project, selection);
   }
 
   public static void setTextAndDescription(@NotNull AnActionEvent e, @NotNull VcsLog log) {
   }
 
   public static void setTextAndDescription(@NotNull AnActionEvent e, @NotNull VcsLog log) {
index 34c65e2fb82cf3bd87c48a590b0b986b7696c80f..ea5ae53812ff1db973530259bb42dc83bf21c4c0 100644 (file)
@@ -128,6 +128,7 @@ abstract class GitStageTree(project: Project,
     val entries = VcsTreeModelData.selected(this).userObjects(GitFileStatusNode::class.java)
     if (entries.size > 1) {
       return ListSelection.createAt(entries, 0)
     val entries = VcsTreeModelData.selected(this).userObjects(GitFileStatusNode::class.java)
     if (entries.size > 1) {
       return ListSelection.createAt(entries, 0)
+        .asExplicitSelection()
     }
 
     val selected = entries.singleOrNull()
     }
 
     val selected = entries.singleOrNull()
@@ -148,6 +149,7 @@ abstract class GitStageTree(project: Project,
     val allEntries = allEntriesData.userObjects(GitFileStatusNode::class.java)
     return if (allEntries.size <= entries.size) {
       ListSelection.createAt(entries, 0)
     val allEntries = allEntriesData.userObjects(GitFileStatusNode::class.java)
     return if (allEntries.size <= entries.size) {
       ListSelection.createAt(entries, 0)
+        .asExplicitSelection()
     }
     else {
       ListSelection.create(allEntries, selected)
     }
     else {
       ListSelection.create(allEntries, selected)