/** @return operation that reverts the effect of the latest local operation in the given editor */ protected Operation calcUndoOperation(SPath editor) { if (!undoHistory.canUndo(editor)) return new NoOperation(); // nothing to undo Operation lastLocal = undoHistory.getLatestLocal(editor); assert lastLocal != null; Operation undoOperation = lastLocal.invert(); for (EditorHistoryEntry entry : undoHistory.entriesToLatestLocal(editor)) { Operation operation = entry.getOperation(); undoOperation = transformation.transform(undoOperation, operation, Boolean.TRUE); log.debug("transformed undo: " + undoOperation); } undoHistory.replaceType(editor, lastLocal, Type.LOCAL, Type.REMOTE); // it is not relevant any more, so it is set remote undoHistory.add(editor, Type.REDOABLE, undoOperation); // save for redo return undoOperation; }
protected void redo(SPath editor) { Operation op = calcRedoOperation(editor); for (TextEditActivity activity : op.toTextEdit(editor, sarosSession.getLocalUser())) { log.debug("redone: " + activity + " in " + editor); fireActivity(activity); } }
protected void undo(SPath editor) { Operation op = calcUndoOperation(editor); log.debug("calculated undo: " + op); // don't waste the network if (op instanceof NoOperation) { log.debug("nothing to undo in " + editor); return; } for (TextEditActivity activity : op.toTextEdit(editor, sarosSession.getLocalUser())) { log.debug("undone: " + activity + " in " + editor); fireActivity(activity); } }
/** @return operation that reverts the effect of the latest undo in the given editor */ protected Operation calcRedoOperation(SPath editor) { if (!undoHistory.canRedo(editor)) return new NoOperation(); // nothing to redo Operation lastUndo = undoHistory.getLatestRedoable(editor); assert lastUndo != null; Operation redoOperation = lastUndo.invert(); for (EditorHistoryEntry entry : undoHistory.entriesToLatestRedoable(editor)) { redoOperation = transformation.transform(redoOperation, entry.getOperation(), Boolean.TRUE); } undoHistory.replaceType(editor, lastUndo, Type.REDOABLE, Type.REMOTE); // it is not relevant any more, so it is set remote undoHistory.add(editor, Type.LOCAL, redoOperation); log.debug("adding " + lastUndo + " (cause: redo internal)"); return redoOperation; }