Very good question and concern to have and good responses so far.
I’ve been in similar situations many times before, where I was on the verge of physically acting out the sin, but stopped before it could be done. However, I see how this is a problem for you because it was enough that we thought about it, and premeditated it. We HAD the intention of doing it, but stopped at the last second…meaning that we WOULD have gone through with it if not for Holy Spirit and/or our guardian angel talking some sense into us and helping us calm or passions or whatever the case is at the right moment. In cases like this, I think it’s still a sin because you willed it to happen, but had a change of heart or were given grace to stop, and God considers that. I think such cases would not be mortal sins.
I would go to confession regardless of whether I had almost committed the sin, however, because it was enough for me to feel guilty that I was so weak and that if just a few more moments or even just a few seconds had gone by, I would have been in mortal sin. Even if in actuality the sin did not occur, the sin existed in my mind and that’s enough for me to want to confess the desire I had to do it, even if I didn’t go through with it physically. The act didn’t happen, but the thoughts did, and that has substance to it and is tangible in it’s own way…tangible enough that it can tempt you in the future and put you into the occasion of sin.
To answer your question directly, no, I don’t think the thought of a mortal sin necessarily equals a mortal sin, nor is ALMOST committing the act count as the same as if you had committed it. If you were possessed to commit murder and did not go through with it, the difference is obvious- the murder did not happen and the person lives. You’d obviously, however, would want to confess this to a priest so he can pray for you and help you out of whatever mentality, illness, or situation that got you there in the first place.
In every day issues, like masturbation as you say, it’s the same thing- you didn’t masturbate even though you might have entertained the thoughts enough that you achieved an erection, or maybe even looked at some pornography. All of these things are sins in their own way however, so you’d need to confess them, especially the pornography, as that is a mortal sin. You’d also want to confess them to get advice from your priest.
The point here is to confess what you DID actually DO. As for the rest, confess it if it’s still sin material or thoughts or desires, but don’t beat yourself up over it. Rather, be glad and rejoice that God gave you what you needed at the right moment to get out of the line of fire. When we’re ‘almost’ in mortal sin, liken it to Satan having a sniper rifle pointed at your soul. He’s got the targeting laser aimed right at your heart, to deliver a mortal wound (mortal sin). He’s got a good lock and he’s ready to fire- but at the last moment, your guardian angel pushes you out of the way and when Satan fires the gun, the bullet zips past where your body was just a moment before, and you’re safe. Realizing you’re in danger and there’s a sniper trying to kill you, you run for cover and protection (confession) and then you’re armed, armored, and safe from future attempts at your life.
I just made up that analogy right now, but I think it works well. Anyone agree?
