Fixed the bug that caused undo history to be lost