Java Code Examples for org.eclipse.jface.text.IUndoManager#undo()

The following examples show how to use org.eclipse.jface.text.IUndoManager#undo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirtyStateEditorSupportIntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=354123
 */
@Test
public void testUndoRedo() throws Exception {
	pushKey('a', 0);
	Assert.assertEquals(1, events.size());
	Assert.assertEquals("fooa", getFirstExportedObjectInLastEventDelta()
			.getQualifiedName().getLastSegment());
	IUndoManager undoManager = ((XtextSourceViewer) editor.getInternalSourceViewer()).getUndoManager();
	undoManager.undo();
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	syncUtil.waitForReconciler(editor);
	Assert.assertEquals(2, events.size());
	Assert.assertNull(Iterables.getLast(events).getDeltas().get(0).getNew());
	undoManager.redo();
	syncUtil.yieldToQueuedDisplayJobs(new NullProgressMonitor());
	syncUtil.waitForReconciler(editor);
	Assert.assertEquals(3, events.size());
	Assert.assertEquals("fooa", getFirstExportedObjectInLastEventDelta()
			.getQualifiedName().getLastSegment());
	Iterables.getLast(events);
}
 
Example 2
Source File: UndoTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testUndo() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val java.lang.String x");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("val java.util.ArrayList<String> y");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtextEditor editor = this._workbenchTestHelper.openEditor("Foo", _builder.toString());
    this._organizeImportsHandler.doOrganizeImports(editor.getDocument());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.ArrayList");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("val String x");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("val ArrayList<String> y");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    Assert.assertEquals(_builder_1.toString(), editor.getDocument().get());
    final ISourceViewer viewer = editor.getInternalSourceViewer();
    Assert.assertTrue((viewer instanceof ITextViewerExtension6));
    final IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
    undoManager.undo();
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("class Foo {");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("val java.lang.String x");
    _builder_2.newLine();
    _builder_2.append("\t");
    _builder_2.append("val java.util.ArrayList<String> y");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    Assert.assertEquals(_builder_2.toString(), editor.getDocument().get());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}