IDEA-61148 Fix Show History for selection with local changes

If local changes were adding or removing lines above the selection,
"show history for selection" used incorrect selection interval,
because it was applied to the latest VCS revision.

Shift the ranges using the existing FindBlock functionality applied
to the current editor content and the latest repository revision.
This commit is contained in:
Kirill Likhodedov
2013-06-20 13:54:06 +04:00
parent 6b35818b05
commit 6d0ec2ec43
2 changed files with 9 additions and 3 deletions
@@ -90,6 +90,7 @@ public class SelectedBlockHistoryAction extends AbstractVcsAction {
final VcsHistoryDialog vcsHistoryDialog =
new VcsHistoryDialog(project,
context.getSelectedFiles()[0],
context.getEditor(),
provider,
session,
activeVcs,
@@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.diff.DiffManager;
import com.intellij.openapi.diff.DiffPanel;
import com.intellij.openapi.diff.SimpleContent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.project.Project;
@@ -56,6 +57,7 @@ import java.util.*;
import java.util.List;
public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
private final Editor myEditor;
private final int mySelectionStart;
private final int mySelectionEnd;
@@ -115,7 +117,7 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
public VcsHistoryDialog(Project project,
final VirtualFile file,
final VcsHistoryProvider vcsHistoryProvider,
Editor editor, final VcsHistoryProvider vcsHistoryProvider,
VcsHistorySession session,
AbstractVcs vcs,
int selectionStart,
@@ -123,6 +125,7 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
final String title, final CachedRevisionsContents cachedContents){
super(project, true);
myProject = project;
myEditor = editor;
mySelectionStart = selectionStart;
mySelectionEnd = selectionEnd;
myCachedContents = cachedContents;
@@ -463,8 +466,10 @@ public class VcsHistoryDialog extends DialogWrapper implements DataProvider {
final String revisionContent = getContentOf(revision);
if (revisionContent == null) return null;
if (index == 0)
myRevisionToContentMap.put(revision, new Block(revisionContent, mySelectionStart, mySelectionEnd));
if (index == 0) {
Block currentBlock = new Block(myEditor.getDocument().getText(), mySelectionStart, mySelectionEnd);
myRevisionToContentMap.put(revision, new FindBlock(revisionContent, currentBlock).getBlockInThePrevVersion());
}
else {
Block prevBlock = getBlock(myRevisions.get(index - 1));
if (prevBlock == null) return null;