mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Autoformat was generating two undo action, the first one being an empty editor. Tested and fixed
This commit is contained in:
parent
c0a1ffa27a
commit
f8aecd0f9c
@ -92,8 +92,10 @@ public class AStyle implements Tool {
|
||||
int line = getLineOfOffset(textArea);
|
||||
int lineOffset = getLineOffset(textArea, line);
|
||||
|
||||
editor.getTextArea().getUndoManager().beginInternalAtomicEdit();
|
||||
editor.setText(formattedText);
|
||||
editor.getSketch().setModified(true);
|
||||
editor.getTextArea().getUndoManager().endInternalAtomicEdit();
|
||||
|
||||
if (line != -1 && lineOffset != -1) {
|
||||
setCaretPosition(textArea, line, lineOffset);
|
||||
|
@ -0,0 +1,56 @@
|
||||
package processing.app;
|
||||
|
||||
import org.fest.swing.fixture.JMenuItemFixture;
|
||||
import org.junit.Test;
|
||||
import processing.app.helpers.RSyntaxTextAreaFixture;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class AutoformatProducesOneUndoActionTest extends AbstractGUITest {
|
||||
|
||||
public static final String SOURCE_BEFORE = "void setup() {\n" +
|
||||
" // put your setup code here, to run once:\n" +
|
||||
"\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"void loop() {\n" +
|
||||
" // put your main code here, to run repeatedly:\n" +
|
||||
"\n" +
|
||||
"}";
|
||||
public static final String SOURCE_AFTER = "void setup() {\n" +
|
||||
" // put your setup code here, to run once:\n" +
|
||||
"\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"void loop() {\n" +
|
||||
" // put your main code here, to run repeatedly:\n" +
|
||||
"\n" +
|
||||
"}";
|
||||
|
||||
@Test
|
||||
public void shouldSaveCaretPositionAfterAutoformat() {
|
||||
JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo");
|
||||
menuEditUndo.requireDisabled();
|
||||
|
||||
JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat");
|
||||
menuToolsAutoFormat.requireEnabled();
|
||||
|
||||
RSyntaxTextAreaFixture editor = window.RSyntaxTextArea("editor");
|
||||
editor.setText(SOURCE_BEFORE);
|
||||
|
||||
editor.setCaretPosition(29); // right before the first // (double slash)
|
||||
|
||||
menuToolsAutoFormat.click();
|
||||
|
||||
String formattedText = editor.getText();
|
||||
assertEquals(SOURCE_AFTER, formattedText);
|
||||
|
||||
assertEquals(29, editor.getCaretPosition());
|
||||
|
||||
menuEditUndo.requireEnabled();
|
||||
menuEditUndo.click();
|
||||
assertEquals(SOURCE_BEFORE, editor.getText());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user