Skip to content

Commit 9dc09e1

Browse files
committed
Merge pull request #2666 from ffissore/undo-redo-fix
Undo sets the sketch to modified, even if it's not
2 parents 94a2c67 + 6d2aa17 commit 9dc09e1

File tree

3 files changed

+56
-24
lines changed

3 files changed

+56
-24
lines changed

app/src/processing/app/Editor.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,7 @@ public UndoAction() {
13651365
public void actionPerformed(ActionEvent e) {
13661366
try {
13671367
undo.undo();
1368+
sketch.setModified(true);
13681369
} catch (CannotUndoException ex) {
13691370
//System.out.println("Unable to undo: " + ex);
13701371
//ex.printStackTrace();
@@ -1386,17 +1387,11 @@ protected void updateUndoState() {
13861387
undoItem.setEnabled(true);
13871388
undoItem.setText(undo.getUndoPresentationName());
13881389
putValue(Action.NAME, undo.getUndoPresentationName());
1389-
if (sketch != null) {
1390-
sketch.setModified(true); // 0107
1391-
}
13921390
} else {
13931391
this.setEnabled(false);
13941392
undoItem.setEnabled(false);
13951393
undoItem.setText(_("Undo"));
13961394
putValue(Action.NAME, "Undo");
1397-
if (sketch != null) {
1398-
sketch.setModified(false); // 0107
1399-
}
14001395
}
14011396
}
14021397
}
@@ -1411,6 +1406,7 @@ public RedoAction() {
14111406
public void actionPerformed(ActionEvent e) {
14121407
try {
14131408
undo.redo();
1409+
sketch.setModified(true);
14141410
} catch (CannotRedoException ex) {
14151411
//System.out.println("Unable to redo: " + ex);
14161412
//ex.printStackTrace();
@@ -1697,10 +1693,12 @@ protected void setCode(SketchCodeDocument codeDoc) {
16971693
document.addUndoableEditListener(new UndoableEditListener() {
16981694
public void undoableEditHappened(UndoableEditEvent e) {
16991695
if (compoundEdit != null) {
1700-
compoundEdit.addEdit(e.getEdit());
1701-
1696+
compoundEdit.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
17021697
} else if (undo != null) {
17031698
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
1699+
}
1700+
if (compoundEdit != null || undo != null) {
1701+
sketch.setModified(true);
17041702
undoAction.updateUndoState();
17051703
redoAction.updateRedoState();
17061704
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package processing.app;
2+
3+
import org.fest.swing.edt.GuiActionRunner;
4+
import org.fest.swing.edt.GuiQuery;
5+
import org.fest.swing.fixture.JMenuItemFixture;
6+
import org.junit.Test;
7+
import processing.app.helpers.JEditTextAreaFixture;
8+
9+
import java.awt.*;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class BlockCommentGeneratesOneUndoActionTest extends AbstractGUITest {
14+
15+
@Test
16+
public void shouldUndoAndRedo() throws Exception {
17+
JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo");
18+
menuEditUndo.requireDisabled();
19+
20+
JEditTextAreaFixture jEditTextArea = window.jEditTextArea("editor");
21+
String previousText = jEditTextArea.getText();
22+
23+
jEditTextArea.selectAll();
24+
25+
GuiActionRunner.execute(new GuiQuery<Frame>() {
26+
27+
protected Frame executeInEDT() {
28+
window.getEditor().handleCommentUncomment();
29+
return window.getEditor();
30+
}
31+
32+
});
33+
34+
menuEditUndo.requireEnabled();
35+
menuEditUndo.click();
36+
37+
assertEquals(previousText, jEditTextArea.getText());
38+
39+
menuEditUndo.requireDisabled();
40+
}
41+
}
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
package processing.app.helpers;
22

3-
import org.fest.swing.core.Robot;
43
import org.fest.swing.fixture.FrameFixture;
4+
import processing.app.Editor;
55
import processing.app.syntax.JEditTextArea;
66

7-
import java.awt.*;
8-
97
public class ArduinoFrameFixture extends FrameFixture {
108

11-
public ArduinoFrameFixture(Frame target) {
12-
super(target);
13-
}
14-
15-
public ArduinoFrameFixture(org.fest.swing.core.Robot robot, Frame target) {
16-
super(robot, target);
17-
}
18-
19-
public ArduinoFrameFixture(Robot robot, String name) {
20-
super(robot, name);
21-
}
9+
private final Editor editor;
2210

23-
public ArduinoFrameFixture(String name) {
24-
super(name);
11+
public ArduinoFrameFixture(Editor editor) {
12+
super(editor);
13+
this.editor = editor;
2514
}
2615

2716
public JEditTextAreaFixture jEditTextArea(String name) {
2817
return new JEditTextAreaFixture(robot, (JEditTextArea) this.robot.finder().find(new JEditTextAreaComponentMatcher(name)));
2918
}
19+
20+
public Editor getEditor() {
21+
return editor;
22+
}
3023
}

0 commit comments

Comments
 (0)