Search in sources :

Example 16 with UndoEdit

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

the class TextEditTests method testInsert5.

@Test
public void testInsert5() throws Exception {
    TextEdit e1 = new InsertEdit(10, "xx");
    fRoot.addChild(e1);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer length", 12, fDocument.getLength());
    assertEquals(fRoot, 10, 2);
    assertEquals(e1, 10, 2);
    Assert.assertEquals("Buffer content", "0123456789xx", fDocument.get());
    doUndoRedo(undo, "0123456789xx");
}
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 17 with UndoEdit

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

the class TextEditTests method testMoveUpWithSourceDelete.

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

Example 18 with UndoEdit

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

the class TextEditTests method testMoveDownWithParentMark.

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

Example 19 with UndoEdit

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

the class TextEditTests method testNestedMoveTarget.

@Test
public void testNestedMoveTarget() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(1, 2);
    MoveSourceEdit s2 = new MoveSourceEdit(5, 3);
    MoveTargetEdit t1 = new MoveTargetEdit(6, s1);
    MoveTargetEdit t2 = new MoveTargetEdit(9, s2);
    s2.addChild(t1);
    fRoot.addChild(s1);
    fRoot.addChild(s2);
    fRoot.addChild(t2);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 1, 0);
    assertEquals(s2, 3, 0);
    assertEquals(t1, 5, 2);
    assertEquals(t2, 4, 5);
    String result = "0348512679";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    doUndoRedo(undo, result);
}
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 20 with UndoEdit

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

the class TextEditTests method testCopyDown.

@Test
public void testCopyDown() throws Exception {
    CopySourceEdit s1 = new CopySourceEdit(2, 3);
    CopyTargetEdit t1 = new CopyTargetEdit(8, s1);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 2, 3);
    assertEquals(t1, 8, 3);
    String result = "0123456723489";
    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)

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