Search in sources :

Example 1 with CopyTargetEdit

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

the class TextEditTests method testNestedCopySource.

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

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

the class TextEditTests method testSwap1.

@Test
public void testSwap1() throws Exception {
    IDocument document = new Document("foo(1, 2), 3");
    MultiTextEdit root = new MultiTextEdit();
    {
        CopySourceEdit innerRoot = new CopySourceEdit(0, 9);
        TextEdit e1 = new ReplaceEdit(0, 9, "");
        e1.addChild(innerRoot);
        CopyTargetEdit t1 = new CopyTargetEdit(11, innerRoot);
        TextEdit e2 = new ReplaceEdit(11, 1, "");
        CopySourceEdit s2 = new CopySourceEdit(11, 1);
        e2.addChild(s2);
        CopyTargetEdit t2 = new CopyTargetEdit(0, s2);
        root.addChild(e1);
        root.addChild(t2);
        root.addChild(e2);
        root.addChild(t1);
    }
    root.apply(document);
    String result = "3, foo(1, 2)";
    Assert.assertEquals("Buffer content", result, document.get());
}
Also used : CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 3 with CopyTargetEdit

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

the class TextEditTests method testDoubleCopy.

@Test
public void testDoubleCopy() throws Exception {
    CopySourceEdit s1 = new CopySourceEdit(5, 2);
    CopyTargetEdit t1 = new CopyTargetEdit(8, s1);
    CopySourceEdit s2 = new CopySourceEdit(5, 2);
    CopyTargetEdit t2 = new CopyTargetEdit(2, s2);
    s1.addChild(s2);
    fRoot.addChild(s1);
    fRoot.addChild(t1);
    fRoot.addChild(t2);
    UndoEdit undo = fRoot.apply(fDocument);
    assertEquals(s1, 7, 2);
    assertEquals(t1, 10, 2);
    assertEquals(s2, 7, 2);
    assertEquals(t2, 2, 2);
    String result = "01562345675689";
    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 4 with CopyTargetEdit

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

the class TextEditTests method testSwap2.

@Test
public void testSwap2() throws Exception {
    IDocument document = new Document("foo(1, 2), 3");
    MultiTextEdit root = new MultiTextEdit();
    {
        TextEdit e1 = new ReplaceEdit(4, 1, "");
        CopySourceEdit s1 = new CopySourceEdit(4, 1);
        e1.addChild(s1);
        CopyTargetEdit t1 = new CopyTargetEdit(7, s1);
        TextEdit e2 = new ReplaceEdit(7, 1, "");
        CopySourceEdit s2 = new CopySourceEdit(7, 1);
        e2.addChild(s2);
        CopyTargetEdit t2 = new CopyTargetEdit(4, s2);
        root.addChild(e1);
        root.addChild(t2);
        root.addChild(e2);
        root.addChild(t1);
    }
    root.apply(document);
    String result = "foo(2, 1), 3";
    Assert.assertEquals("Buffer content", result, document.get());
}
Also used : CopySourceEdit(org.eclipse.text.edits.CopySourceEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CopyTargetEdit(org.eclipse.text.edits.CopyTargetEdit) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 5 with CopyTargetEdit

use of org.eclipse.text.edits.CopyTargetEdit 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

CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)12 CopyTargetEdit (org.eclipse.text.edits.CopyTargetEdit)12 Test (org.junit.Test)10 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)6 TextEdit (org.eclipse.text.edits.TextEdit)6 UndoEdit (org.eclipse.text.edits.UndoEdit)6 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)4 Document (org.eclipse.jface.text.Document)3 IDocument (org.eclipse.jface.text.IDocument)3 InsertEdit (org.eclipse.text.edits.InsertEdit)2 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)2 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)1 TextEditCopier (org.eclipse.text.edits.TextEditCopier)1