Feature Request: Save File on loss of focus
If I switch to a different window, automatically save the file I was working on.
There’s an AutoSave plugin. It has been a bit of time since I used it last, so I can’t say for sure if it does exactly what you are looking for; it may be worth checking out to see if it meets your need.
Your desired behavior could also be scripted with a scripting plugin.