Try this to break the cycle: Go Analytic!
When you begin to doubt, or don't know what to write next, Start a new paragraph with some knots (&&&) and explain why what you wrote doesn't work. It is true dialogue should generally be concise, but your note does not have to be: write in as confused and rambling a screed as needed what you were trying to tell the reader that the previous crap fails to convey.
Or perhaps you are stuck on the plot, and what comes next. If so write about that. Then, instead of erasing it, leave your note there, and
&&& TRY AGAIN:
I use knots for inline notes in a story, so I can search later and delete the notes. I can type these 3 characters without my fingers ever leaving the keyboard to find a button or use a mouse. But you could do the same on a new page, in different color ink, in a new document, etc.
Whenever you get into the cycle of delete and rewrite, stop deleting: Write out what is bothering you. The only time to delete is when you have arrived at a final iteration of what you want: And even then, I'd give it a week, and reread, and see if you want to analyze further.
In my view, delete and rewrite is like taking blindfold shots at a target; it means I am just guessing at what might work and my subconscious story editor is never satisfied that what I wrote is going to work in the story.
So why doesn't something "work" in a story? Is it dialogue contrary to what I want the character to be? Is it going to move the characters in the wrong direction, or into a dead end I can't get them out of? Is there a more pressing conflict that this fails to resolve?
There is a problem, a knot to untie, and the only way to do it is to understand precisely why my subconscious is reacting with dislike to the words on the page. So I need to stop taking potshots at it, and start a stream of consciousness critique of why, exactly why, this bit of writing sucks.
By not deleting these notes, you keep a record of every iteration and alternative; every attempt to get better, and remember your own previous critiques, like Theseus using his ball of thread to escape the Minotaur's labyrinth.
When you can come back to some iteration days later, and still like what you wrote: Copy your notes and previous iterations (and final draft) to another Notes document and delete all but the final draft from your main document; hopefully never to be consulted again. If you ever do doubt it again: Go to your writing notes and search for the final draft; you can retrieve all that analysis then, and if necessary, add to it.
Never delete anything; you will inevitably forget what you have already tried and try it again, perpetuating a cycle: X didn't work, how about Y? No, Y doesn't work, how about Z? No Z doesn't work ... ... how about X?
To answer the question: This helps you stay confident because you will personally know, after this analysis and by your notes and knots, that what you have is what the story really needs. Lack of confidence is doubt; analysis will remove the doubt, and keeping a record of it will help you to dispel the doubt if it creeps back.