1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Compound edits weren't part of the undo/redo dance

This commit is contained in:
Federico Fissore 2015-02-19 13:40:21 +01:00
parent cad74c5f7c
commit 6d2aa17051
3 changed files with 53 additions and 18 deletions

View File

@ -1693,10 +1693,11 @@ public class Editor extends JFrame implements RunnerListener {
document.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) {
if (compoundEdit != null) {
compoundEdit.addEdit(e.getEdit());
compoundEdit.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
} else if (undo != null) {
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
}
if (compoundEdit != null || undo != null) {
sketch.setModified(true);
undoAction.updateUndoState();
redoAction.updateRedoState();

View File

@ -0,0 +1,41 @@
package processing.app;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.fixture.JMenuItemFixture;
import org.junit.Test;
import processing.app.helpers.JEditTextAreaFixture;
import java.awt.*;
import static org.junit.Assert.assertEquals;
public class BlockCommentGeneratesOneUndoActionTest extends AbstractGUITest {
@Test
public void shouldUndoAndRedo() throws Exception {
JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo");
menuEditUndo.requireDisabled();
JEditTextAreaFixture jEditTextArea = window.jEditTextArea("editor");
String previousText = jEditTextArea.getText();
jEditTextArea.selectAll();
GuiActionRunner.execute(new GuiQuery<Frame>() {
protected Frame executeInEDT() {
window.getEditor().handleCommentUncomment();
return window.getEditor();
}
});
menuEditUndo.requireEnabled();
menuEditUndo.click();
assertEquals(previousText, jEditTextArea.getText());
menuEditUndo.requireDisabled();
}
}

View File

@ -1,30 +1,23 @@
package processing.app.helpers;
import org.fest.swing.core.Robot;
import org.fest.swing.fixture.FrameFixture;
import processing.app.Editor;
import processing.app.syntax.JEditTextArea;
import java.awt.*;
public class ArduinoFrameFixture extends FrameFixture {
public ArduinoFrameFixture(Frame target) {
super(target);
}
private final Editor editor;
public ArduinoFrameFixture(org.fest.swing.core.Robot robot, Frame target) {
super(robot, target);
}
public ArduinoFrameFixture(Robot robot, String name) {
super(robot, name);
}
public ArduinoFrameFixture(String name) {
super(name);
public ArduinoFrameFixture(Editor editor) {
super(editor);
this.editor = editor;
}
public JEditTextAreaFixture jEditTextArea(String name) {
return new JEditTextAreaFixture(robot, (JEditTextArea) this.robot.finder().find(new JEditTextAreaComponentMatcher(name)));
}
public Editor getEditor() {
return editor;
}
}