use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMoveWithTargetDelete.
@Test
public void testMoveWithTargetDelete() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(2, 3);
MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
TextEdit e2 = new DeleteEdit(6, 2);
e2.addChild(t1);
fRoot.addChild(s1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "01589", fDocument.get());
assertEquals(s1, 2, 0);
assertTrue(t1.isDeleted());
assertEquals(e2, 3, 0);
doUndoRedo(undo, "01589");
}
use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testTreeUpdate1.
@Test
public void testTreeUpdate1() throws Exception {
MultiTextEdit m1 = new MultiTextEdit();
TextEdit e1 = new InsertEdit(2, "aa");
TextEdit e2 = new InsertEdit(4, "bb");
m1.addChild(e1);
m1.addChild(e2);
MultiTextEdit m2 = new MultiTextEdit();
TextEdit e3 = new InsertEdit(6, "cc");
TextEdit e4 = new InsertEdit(8, "dd");
m2.addChild(e3);
m2.addChild(e4);
fRoot.addChild(m1);
fRoot.addChild(m2);
assertEquals(m1, 2, 2);
assertEquals(m2, 6, 2);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "01aa23bb45cc67dd89", fDocument.get());
assertEquals(e1, 2, 2);
assertEquals(e2, 6, 2);
assertEquals(e3, 10, 2);
assertEquals(e4, 14, 2);
assertEquals(m1, 2, 6);
assertEquals(m2, 10, 6);
assertEquals(fRoot, 2, 14);
doUndoRedo(undo, "01aa23bb45cc67dd89");
}
use of org.eclipse.text.edits.UndoEdit in project che by eclipse.
the class TextChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 3);
IDocument document = null;
try {
document = acquireDocument(new SubProgressMonitor(pm, 1));
UndoEdit undo = performEdits(document);
commit(document, new SubProgressMonitor(pm, 1));
return createUndoChange(undo);
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
} catch (MalformedTreeException e) {
throw Changes.asCoreException(e);
} finally {
releaseDocument(document, new SubProgressMonitor(pm, 1));
pm.done();
}
}
use of org.eclipse.text.edits.UndoEdit in project che by eclipse.
the class UndoTextFileChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
boolean[] setContentStampSuccess = { false };
UndoEdit redo = performEdits(buffer, document, setContentStampSuccess);
if (needsSaving()) {
buffer.commit(pm, false);
if (!setContentStampSuccess[0]) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange(redo, currentStamp);
} catch (BadLocationException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw Changes.asCoreException(e);
else
return new NullChange();
} catch (MalformedTreeException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw Changes.asCoreException(e);
else
return new NullChange();
} catch (CoreException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw e;
else
return new NullChange();
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.text.edits.UndoEdit in project che by eclipse.
the class MultiStateTextFileChange method performChangesInSynchronizationContext.
private void performChangesInSynchronizationContext(final IDocument document, final LinkedList undoList, final boolean preview) throws BadLocationException {
DocumentRewriteSession session = null;
try {
if (document instanceof IDocumentExtension4)
session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
for (final Iterator iterator = fChanges.iterator(); iterator.hasNext(); ) {
final ComposableBufferChange change = (ComposableBufferChange) iterator.next();
final UndoEdit edit = createTextEditProcessor(change, document, undoList != null ? TextEdit.CREATE_UNDO : TextEdit.NONE, preview).performEdits();
if (undoList != null)
undoList.addFirst(edit);
}
} finally {
if (session != null)
((IDocumentExtension4) document).stopRewriteSession(session);
}
}
Aggregations