Search in sources :

Example 41 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMove2.

@Test
public void testMove2() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(5, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0156234789", fDocument.get());
    assertEquals(s1, 7, 0);
    assertEquals(t1, 2, 2);
    doUndoRedo(undo, "0156234789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 42 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMove1.

@Test
public void testMove1() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 2);
    MoveTargetEdit t1 = new MoveTargetEdit(5, s1);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "0142356789", fDocument.get());
    assertEquals(s1, 2, 0);
    assertEquals(t1, 3, 2);
    doUndoRedo(undo, "0142356789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 43 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testInsert4.

@Test
public void testInsert4() throws Exception {
    TextEdit e1 = new InsertEdit(0, "xx");
    fRoot.addChild(e1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer length", 12, fDocument.getLength());
    assertEquals(fRoot, 0, 2);
    assertEquals(e1, 0, 2);
    Assert.assertEquals("Buffer content", "xx0123456789", fDocument.get());
    doUndoRedo(undo, "xx0123456789");
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 44 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testCopyUp.

@Test
public void testCopyUp() throws Exception {
    CopySourceEdit s1 = new CopySourceEdit(7, 2);
    CopyTargetEdit t1 = new CopyTargetEdit(3, s1);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 9, 2);
    assertEquals(t1, 3, 2);
    String result = "012783456789";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    doUndoRedo(undo, result);
}
Also used : CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 45 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method doUndoRedo.

private void doUndoRedo(UndoEdit undo, String redoResult) throws Exception {
    UndoEdit redo = undo.apply(fDocument);
    assertBufferContent();
    undo = redo.apply(fDocument);
    Assert.assertEquals("Buffer content redo", redoResult, fDocument.get());
    undo.apply(fDocument);
    assertBufferContent();
}
Also used : UndoEdit(org.eclipse.text.edits.UndoEdit)

Aggregations

UndoEdit (org.eclipse.text.edits.UndoEdit)53 Test (org.junit.Test)40 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)25 TextEdit (org.eclipse.text.edits.TextEdit)25 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)23 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)23 InsertEdit (org.eclipse.text.edits.InsertEdit)12 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)12 BadLocationException (org.eclipse.jface.text.BadLocationException)10 DeleteEdit (org.eclipse.text.edits.DeleteEdit)9 RangeMarker (org.eclipse.text.edits.RangeMarker)8 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)6 CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)6 CopyTargetEdit (org.eclipse.text.edits.CopyTargetEdit)6 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IDocument (org.eclipse.jface.text.IDocument)4 Lock (org.eclipse.ltk.internal.core.refactoring.Lock)3 LinkedList (java.util.LinkedList)2