Search in sources :

Example 36 with UndoEdit

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

the class TextEditTests method testNestedCopyTarget.

@Test
public void testNestedCopyTarget() throws Exception {
    CopySourceEdit s1 = new CopySourceEdit(1, 2);
    CopySourceEdit s2 = new CopySourceEdit(5, 3);
    CopyTargetEdit t1 = new CopyTargetEdit(6, s1);
    CopyTargetEdit t2 = new CopyTargetEdit(9, s2);
    s2.addChild(t1);
    fRoot.addChild(s1);
    fRoot.addChild(s2);
    fRoot.addChild(t2);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 1, 2);
    assertEquals(s2, 5, 5);
    assertEquals(t1, 6, 2);
    assertEquals(t2, 11, 5);
    String result = "01234512678512679";
    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 37 with UndoEdit

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

the class TextEditTests method testNestedMoveSourceWithInsert.

@Test
public void testNestedMoveSourceWithInsert() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(1, 5);
    MoveSourceEdit s2 = new MoveSourceEdit(2, 3);
    MoveSourceEdit s3 = new MoveSourceEdit(3, 1);
    InsertEdit i1 = new InsertEdit(4, "x");
    s1.addChild(s2);
    s2.addChild(s3);
    s3.addChild(i1);
    MoveTargetEdit t1 = new MoveTargetEdit(9, s1);
    MoveTargetEdit t2 = new MoveTargetEdit(8, s2);
    MoveTargetEdit t3 = new MoveTargetEdit(7, s3);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    fRoot.addChild(t2);
    fRoot.addChild(t3);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 1, 0);
    assertEquals(s2, 9, 0);
    assertEquals(s3, 6, 0);
    assertEquals(i1, 3, 1);
    assertEquals(t1, 8, 2);
    assertEquals(t2, 5, 2);
    assertEquals(t3, 2, 2);
    String result = "063x7248159";
    Assert.assertEquals("Buffer content", result, fDocument.get());
    doUndoRedo(undo, result);
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 38 with UndoEdit

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

the class TextEditTests method testDelete2.

@Test
public void testDelete2() throws Exception {
    TextEdit e1 = new DeleteEdit(4, 1);
    TextEdit e2 = new DeleteEdit(3, 1);
    TextEdit e3 = new DeleteEdit(5, 1);
    fRoot.addChild(e1);
    fRoot.addChild(e2);
    fRoot.addChild(e3);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(fRoot, 3, 0);
    assertEquals(e1, 3, 0);
    assertEquals(e2, 3, 0);
    assertEquals(e3, 3, 0);
    Assert.assertEquals("Buffer content", "0126789", fDocument.get());
    doUndoRedo(undo, "0126789");
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 39 with UndoEdit

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

the class TextEditTests method testDelete1.

@Test
public void testDelete1() throws Exception {
    TextEdit e1 = new DeleteEdit(3, 1);
    fRoot.addChild(e1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(fRoot, 3, 0);
    assertEquals(e1, 3, 0);
    Assert.assertEquals("Buffer content", "012456789", fDocument.get());
    doUndoRedo(undo, "012456789");
}
Also used : MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 40 with UndoEdit

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

the class TextEditTests method testMove6.

@Test
public void testMove6() throws Exception {
    // Move onto itself
    MoveSourceEdit s1 = new MoveSourceEdit(2, 1);
    MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
    TextEdit e2 = new ReplaceEdit(2, 1, "x");
    s1.addChild(e2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 3, 0);
    assertEquals(t1, 2, 1);
    assertEquals(e2, 2, 1);
    Assert.assertEquals("Buffer content", "01x3456789", fDocument.get());
    doUndoRedo(undo, "01x3456789");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) 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