From 6d0ec2ec43cd0ece80661a757b776dffc9953b48 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 20 Jun 2013 13:51:31 +0400 Subject: [PATCH] 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. --- .../vcs/actions/SelectedBlockHistoryAction.java | 1 + .../openapi/vcs/history/impl/VcsHistoryDialog.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java index 867c009ba775..a899185e8ec8 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/SelectedBlockHistoryAction.java @@ -90,6 +90,7 @@ public class SelectedBlockHistoryAction extends AbstractVcsAction { final VcsHistoryDialog vcsHistoryDialog = new VcsHistoryDialog(project, context.getSelectedFiles()[0], + context.getEditor(), provider, session, activeVcs, diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java index 2dbbf7357cf5..0952fa2861df 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsHistoryDialog.java @@ -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;