Fix undo bug

issue #2398#issuecomment-37761224