My guess is that the code tries to sync the source to the position withing the table of content and it does not work because TOC is in a separate file. But to an uninitiated user it looks like "things are broken".
I don't know how generic this issue is, but natural fixes seems to be:
- if you cannot move to the desired location, keep the source window as is
- specifically for TOC - it may focus the command that inserts TOC into the main document, since such behaviour should result in smooth scrolling without any jumps. But I am not sure, actually, if it will be easy to detect any difference compared to 1) which sounds easier.