diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java index daef43857c4e..8a9e40582eb0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java @@ -295,6 +295,23 @@ public class LineStatusTracker { } } + private void markFileUnchanged() { + ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override + public void run() { + FileDocumentManager.getInstance().saveDocument(myDocument); + boolean stillEmpty; + synchronized (myLock) { + stillEmpty = myRanges.isEmpty(); + } + if (stillEmpty) { + // file was modified, and now it's not -> dirty local change + myVcsDirtyScopeManager.fileDirty(myVirtualFile); + } + } + }); + } + private class MyDocumentListener extends DocumentAdapter { // We have 3 document versions: // * VCS version @@ -457,20 +474,7 @@ public class LineStatusTracker { } if (myRanges.isEmpty() && myVirtualFile != null) { - ApplicationManager.getApplication().invokeLater(new Runnable() { - @Override - public void run() { - FileDocumentManager.getInstance().saveDocument(myDocument); - boolean stillEmpty; - synchronized (myLock) { - stillEmpty = myRanges.isEmpty(); - } - if (stillEmpty) { - // file was modified, and now it's not -> dirty local change - myVcsDirtyScopeManager.fileDirty(myVirtualFile); - } - } - }); + markFileUnchanged(); } } } @@ -828,6 +832,34 @@ public class LineStatusTracker { } } + public void rollbackChanges() { + myApplication.assertWriteAccessAllowed(); + + synchronized (myLock) { + if (myBulkUpdate) return; + + try { + mySuppressUpdate = true; + + myDocument.setText(myVcsDocument.getText()); + + removeAnathema(); + removeHighlightersFromMarkupModel(); + + markFileUnchanged(); + } + catch (Throwable e) { + reinstallRanges(); + if (e instanceof Error) throw ((Error)e); + if (e instanceof RuntimeException) throw ((RuntimeException)e); + throw new RuntimeException(e); + } + finally { + mySuppressUpdate = false; + } + } + } + public CharSequence getVcsContent(@NotNull Range range) { synchronized (myLock) { TextRange textRange = getVcsRange(range); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java index 1286b6815fcf..c86f6047abc1 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java @@ -12,8 +12,6 @@ */ package com.intellij.openapi.vcs.ex; -import com.intellij.icons.AllIcons; -import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.application.ApplicationManager; @@ -73,6 +71,15 @@ public class RollbackLineStatusAction extends DumbAwareAction { BitSet lines = new BitSet(totalLines + 1); List carets = editor.getCaretModel().getAllCarets(); + + if (carets.size() == 1) { + Caret caret = carets.get(0); + if (caret.getSelectionStart() == 0 && caret.getSelectionEnd() == document.getTextLength()) { + doRollback(tracker); + return; + } + } + for (Caret caret : carets) { if (caret.hasSelection()) { int line1 = editor.offsetToLogicalPosition(caret.getSelectionStart()).line; @@ -107,6 +114,15 @@ public class RollbackLineStatusAction extends DumbAwareAction { }); } + private static void doRollback(@NotNull final LineStatusTracker tracker) { + execute(tracker, new Runnable() { + @Override + public void run() { + tracker.rollbackChanges(); + } + }); + } + private static void execute(@NotNull final LineStatusTracker tracker, @NotNull final Runnable task) { CommandProcessor.getInstance().executeCommand(tracker.getProject(), new Runnable() { public void run() {