mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: special case for 'Ctrl+A' + 'Ctrl+Alt+Z' combination
In case of reverting of whole file - mark file dirty, so the 'saveAll()' did not trim spaces. So the state of the file after this 'combo' should be 'unmodified', without any IDE-generated changes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<Caret> 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() {
|
||||
|
||||
Reference in New Issue
Block a user