Train of thought
@AzulCrescent in this situation, you could also say the train of thought got derailed, which is a common joke when your attention got diverted and you can't remember what you were thinking about. :-)