Fixed "undo" functionality for replaceAll function