I have also tried to do this, but it seemed to be pretty complicated, so I didn’t manage to implement it. I think this is way too hard, and I have complained about it before.
I know there was a blog post somehwere explaining how it could be done, but I can’t find it anymore