Skip to content

Commit 6d2aa17

Browse files
author
Federico Fissore
committed
Compound edits weren't part of the undo/redo dance
1 parent cad74c5 commit 6d2aa17

File tree

3 files changed

+53
-18
lines changed

3 files changed

+53
-18
lines changed

app/src/processing/app/Editor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,10 +1693,11 @@ protected void setCode(SketchCodeDocument codeDoc) {
16931693
document.addUndoableEditListener(new UndoableEditListener() {
16941694
public void undoableEditHappened(UndoableEditEvent e) {
16951695
if (compoundEdit != null) {
1696-
compoundEdit.addEdit(e.getEdit());
1697-
1696+
compoundEdit.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
16981697
} else if (undo != null) {
16991698
undo.addEdit(new CaretAwareUndoableEdit(e.getEdit(), textarea));
1699+
}
1700+
if (compoundEdit != null || undo != null) {
17001701
sketch.setModified(true);
17011702
undoAction.updateUndoState();
17021703
redoAction.updateRedoState();
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)