[diff/merge] IDEA-59513 scroll to the first conflicting change after applying "all non-conflicting changes"

Let LineBlocks#getBeginnings return only applied changes, and use this method to scroll in the merge tool to ignore applied changes when scrolling to the first change.
This commit is contained in:
Kirill Likhodedov
2012-07-22 14:58:11 +04:00
parent ba7ac90ad5
commit f2a6d145e0
3 changed files with 36 additions and 11 deletions
@@ -22,17 +22,22 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.diff.DiffBundle;
import com.intellij.openapi.diff.impl.incrementalMerge.Change;
import com.intellij.openapi.diff.impl.incrementalMerge.MergeList;
import com.intellij.openapi.diff.impl.util.DiffPanelOuterComponent;
import com.intellij.openapi.project.DumbAware;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.FilteringIterator;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ApplyNonConflicts extends AnAction implements DumbAware {
public ApplyNonConflicts() {
@Nullable private final DiffPanelOuterComponent myDiffPanel;
public ApplyNonConflicts(@Nullable DiffPanelOuterComponent diffPanel) {
super(DiffBundle.message("merge.dialog.apply.all.non.conflicting.changes.action.name"), null, AllIcons.Diff.ApplyNotConflicts);
myDiffPanel = diffPanel;
}
public void actionPerformed(AnActionEvent e) {
@@ -41,6 +46,9 @@ public class ApplyNonConflicts extends AnAction implements DumbAware {
for (Change change : notConflicts) {
Change.apply(change, MergeList.BRANCH_SIDE);
}
if (myDiffPanel != null) {
myDiffPanel.requestScrollEditors();
}
}
public void update(AnActionEvent e) {
@@ -145,7 +145,7 @@ public class MergePanel2 implements DiffViewer {
toolbar.addAction(new OpenPartialDiffAction(1, 2, AllIcons.Diff.RightDiff));
toolbar.addAction(new OpenPartialDiffAction(0, 2, AllIcons.Diff.BranchDiff));
toolbar.addSeparator();
toolbar.addAction(new ApplyNonConflicts());
toolbar.addAction(new ApplyNonConflicts(myPanel));
toolbar.addSeparator();
toolbar.addAction(new MergeToolSettingsAction(getEditors()));
}
@@ -414,7 +414,7 @@ public class MergePanel2 implements DiffViewer {
private int[] getPrimaryBeginnings(DiffDividerPaint paint) {
FragmentSide primarySide = paint.getLeftSide();
LOG.assertTrue(getEditor(1) == paint.getSides().getEditor(primarySide));
return paint.getSides().getLineBlocks().getBeginnings(primarySide);
return paint.getSides().getLineBlocks().getBeginnings(primarySide, true);
}
}
@@ -22,7 +22,7 @@ import com.intellij.openapi.diff.impl.highlighting.FragmentSide;
import com.intellij.openapi.diff.impl.incrementalMerge.Change;
import com.intellij.openapi.diff.impl.incrementalMerge.ChangeList;
import com.intellij.openapi.diff.impl.util.TextDiffType;
import com.intellij.util.containers.IntArrayList;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -61,16 +61,33 @@ public class LineBlocks {
return getBeginnings(FragmentSide.SIDE1).length;
}
/**
* Get beginnings of all the changes from the specified side.
* @param side Side of the changes.
*/
public int[] getBeginnings(FragmentSide side) {
IntArrayList result = new IntArrayList(getIntervals(side).length);
return getBeginnings(side, false);
}
/**
* Get beginnings of the changes from the specified side.
* @param side Side of the changes.
* @param unappliedOnly If true - only unapplied changes will be considered, if false - all changes (both applied and not applied).
*/
public int[] getBeginnings(FragmentSide side, boolean unappliedOnly) {
List<Integer> result = new ArrayList<Integer>(myDiffs.size());
int previousBeginning = Integer.MIN_VALUE;
Interval[] sideIntervals = getIntervals(side);
for (Interval sideInterval : sideIntervals) {
int start = sideInterval.getStart();
if (start != previousBeginning) result.add(start);
previousBeginning = start;
for (Diff diff : myDiffs) {
if (!unappliedOnly || !diff.getDiffType().isApplied()) {
Interval interval = diff.getInterval(side);
int start = interval.getStart();
if (start != previousBeginning) result.add(start);
previousBeginning = start;
}
}
return result.toArray();
return ArrayUtil.toIntArray(result);
}
static int getMaxStartedIndex(Interval[] intervals, int start) {