mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-100907 Undo replace while doing regex replace would undo the regex change instead of the replace
This commit is contained in:
@@ -86,8 +86,8 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
|
||||
private JTextComponent mySearchField;
|
||||
private JTextComponent myReplaceField;
|
||||
private TextComponentUndoProvider mySearchUndo;
|
||||
private TextComponentUndoProvider myReplaceUndo;
|
||||
private MyUndoProvider mySearchUndo;
|
||||
private MyUndoProvider myReplaceUndo;
|
||||
|
||||
private Getter<JTextComponent> mySearchFieldGetter = new Getter<JTextComponent>() {
|
||||
@Override
|
||||
@@ -279,7 +279,7 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
mySearchUndo.dispose();
|
||||
}
|
||||
mySearchField = createTextField(myLeadPanel);
|
||||
mySearchUndo = new TextComponentUndoProvider(mySearchField);
|
||||
mySearchUndo = new MyUndoProvider(mySearchField);
|
||||
|
||||
setupSearchFieldListener();
|
||||
|
||||
@@ -507,7 +507,7 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
myReplaceUndo.dispose();
|
||||
}
|
||||
myReplaceField = createTextField(myReplacementPane);
|
||||
myReplaceUndo = new TextComponentUndoProvider(myReplaceField);
|
||||
myReplaceUndo = new MyUndoProvider(myReplaceField);
|
||||
|
||||
//if (myToolbarComponent instanceof ActionToolbarImpl) {
|
||||
// new ShowMoreOptions(myToolbarComponent, myReplaceField);
|
||||
@@ -904,6 +904,34 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
return insets;
|
||||
}
|
||||
|
||||
private static class MyUndoProvider extends TextComponentUndoProvider {
|
||||
private boolean myEnabled = true;
|
||||
public MyUndoProvider(JTextComponent textComponent) {
|
||||
super(textComponent);
|
||||
textComponent.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() {
|
||||
@Override
|
||||
protected void textChanged(javax.swing.event.DocumentEvent e) {
|
||||
myEnabled = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canUndo() {
|
||||
return super.canUndo() && myEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canRedo() {
|
||||
return super.canRedo() && myEnabled;
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
myEnabled = false;
|
||||
myUndoManager.discardAllEdits();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyLivePreviewController extends LivePreviewControllerBase {
|
||||
public MyLivePreviewController() {
|
||||
super(EditorSearchComponent.this.mySearchResults, EditorSearchComponent.this.myLivePreview);
|
||||
@@ -941,7 +969,8 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
mySuppressUpdate = false;
|
||||
}
|
||||
//getFocusBack();
|
||||
addTextToRecent(myReplaceField) ;
|
||||
addTextToRecent(myReplaceField);
|
||||
clearUndoInTextFields();
|
||||
}
|
||||
|
||||
public void exclude() {
|
||||
@@ -952,4 +981,9 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data
|
||||
performReplaceAll(myEditor);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearUndoInTextFields() {
|
||||
myReplaceUndo.disable();
|
||||
mySearchUndo.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import javax.swing.undo.UndoManager;
|
||||
* @author yole
|
||||
*/
|
||||
public class TextComponentUndoProvider implements Disposable {
|
||||
private final JTextComponent myTextComponent;
|
||||
private final UndoManager myUndoManager = new UndoManager();
|
||||
protected final JTextComponent myTextComponent;
|
||||
protected final UndoManager myUndoManager = new UndoManager();
|
||||
private UndoableEditListener myUndoableEditListener;
|
||||
|
||||
public TextComponentUndoProvider(final JTextComponent textComponent) {
|
||||
@@ -47,27 +47,53 @@ public class TextComponentUndoProvider implements Disposable {
|
||||
Shortcut[] redoShortcuts = activeKeymap.getShortcuts(IdeActions.ACTION_REDO);
|
||||
|
||||
AnAction undoAction = new AnAction() {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(canUndo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
if (myUndoManager.canUndo()) {
|
||||
myUndoManager.undo();
|
||||
}
|
||||
undo();
|
||||
}
|
||||
};
|
||||
|
||||
AnAction redoAction = new AnAction() {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(canRedo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
if (myUndoManager.canRedo()) {
|
||||
myUndoManager.redo();
|
||||
}
|
||||
redo();
|
||||
}
|
||||
};
|
||||
|
||||
undoAction.registerCustomShortcutSet(new CustomShortcutSet(undoShortcuts), myTextComponent);
|
||||
redoAction.registerCustomShortcutSet(new CustomShortcutSet(redoShortcuts), myTextComponent);
|
||||
}
|
||||
|
||||
protected boolean canUndo() {
|
||||
return myUndoManager.canUndo();
|
||||
}
|
||||
|
||||
protected boolean canRedo() {
|
||||
return myUndoManager.canRedo();
|
||||
}
|
||||
|
||||
protected void redo() {
|
||||
if (myUndoManager.canRedo()) {
|
||||
myUndoManager.redo();
|
||||
}
|
||||
}
|
||||
|
||||
protected void undo() {
|
||||
if (myUndoManager.canUndo()) {
|
||||
myUndoManager.undo();
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||
Reference in New Issue
Block a user