Yes, it happens that sometimes you have a lot of ideas at unexpected moments and well... something I do now is to always carry a mini physical notebook and write down as briefly as possible the idea.
Generally, when I do that, I calm down. Then there is the part where ok, it's time to see how to get to that idea and well, instead of falling into despair (which I used to fall too much) I sit in front of the orderly and look at everything I have written.
If I know or feel that it's going to take me a long time to get to the idea, the best solution I've found is... to ignore it.
The reason?
Well, getting desperate to try to get to that "epic scene" or "insert heart-pounding moment.exe" at the end... I feel like it ends up ruining me and my story by just trying to get to the development of that idea.
So, now simply:
Can I come up with a good idea?
I write it down. I'll see how I'll implement it later, but I try to constantly follow my novel until I get to those parts I always wanted to tell.
Is it slow? Yes.
Do I make mistakes? Yes.
The point is that I manage not to get stuck or make the mistake of rewriting my work for the sixteenth time.
My current point of view is that works don't have to be perfect, at least if you write for fun.
The work will always have flaws, I am not inviting mediocrity, but to accept that, at least if we never wrote or mastered a certain language to perfection, we should not expect to create a masterpiece in our first attempts.
Cheer up and I hope you find your working method to write better!