It can be a common solution of #302, #369, #962 etc.
we need it for #1208
It seems, that I'll not complete the work on this issue in the near future. Here is my draft. It can be used if needed.