When you edit a script and accidentally go to another script without having saved your changes, the edits are lost. Could you add a warning in this case?
The simplest way would be the standard “do you really want to navigate away from this page?”, more elaborate would be “save or discard your changes”.