diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 7313f61f2..8c7ec1db3 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1365,6 +1365,7 @@ public class Editor extends JFrame implements RunnerListener { public void actionPerformed(ActionEvent e) { try { undo.undo(); + sketch.setModified(true); } catch (CannotUndoException ex) { //System.out.println("Unable to undo: " + ex); //ex.printStackTrace(); @@ -1386,17 +1387,11 @@ public class Editor extends JFrame implements RunnerListener { undoItem.setEnabled(true); undoItem.setText(undo.getUndoPresentationName()); putValue(Action.NAME, undo.getUndoPresentationName()); - if (sketch != null) { - sketch.setModified(true); // 0107 - } } else { this.setEnabled(false); undoItem.setEnabled(false); undoItem.setText(_("Undo")); putValue(Action.NAME, "Undo"); - if (sketch != null) { - sketch.setModified(false); // 0107 - } } } } @@ -1411,6 +1406,7 @@ public class Editor extends JFrame implements RunnerListener { public void actionPerformed(ActionEvent e) { try { undo.redo(); + sketch.setModified(true); } catch (CannotRedoException ex) { //System.out.println("Unable to redo: " + ex); //ex.printStackTrace(); @@ -1697,10 +1693,12 @@ 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(); } diff --git a/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java b/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java new file mode 100644 index 000000000..555a03fcc --- /dev/null +++ b/app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java @@ -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() { + + protected Frame executeInEDT() { + window.getEditor().handleCommentUncomment(); + return window.getEditor(); + } + + }); + + menuEditUndo.requireEnabled(); + menuEditUndo.click(); + + assertEquals(previousText, jEditTextArea.getText()); + + menuEditUndo.requireDisabled(); + } +} diff --git a/app/test/processing/app/helpers/ArduinoFrameFixture.java b/app/test/processing/app/helpers/ArduinoFrameFixture.java index aec49a5a8..a5832a904 100644 --- a/app/test/processing/app/helpers/ArduinoFrameFixture.java +++ b/app/test/processing/app/helpers/ArduinoFrameFixture.java @@ -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; + } }