You are far smarter than you think.
Learn to get into flow, and also figure out how to get your state back faster... Once you do, it is a super power.
Simple things like leaving your editor/IDE open, create the same situation you left. I personally use music + IEMs to help me block sound and focus. -30-35 DB off the IEMs, and +70DB off my music... yeah, I don't hear anything.
I learned the editor trick recently, though I'd probably done it un-intentionally for years. I stopped, and I was wondering what the inertia I was facing was. It is only 2-3m to get setup... that's 2-3m to lose my thoughts, etc.
Good luck.