I have not been diagnosed with ADHD, nor do I think I have all the symptoms of it (the way I see people on ADHD subreddit talk about), but I totally understand the thing you're describing.
I do have a problem with focus while working. One thing which really helps me is if I put on some audiobook I don't really care to focus on too much about, or some podcast or lecture, but it helps me focus. Not all the time, but say I am working on solving a coding challenge, then the part where I figure out which solution would work, I can't listen to anything and I need to focus, but the part where I actually implement the solution(especially if I have implemented something like that many times) then I can only do it if there is something else to distract other parts of my mind.