Did you catch the parallel? John tells Mary “It was just texting” that “she was just a woman who smiled” – that the attention made him feel good, that she wasn’t everything, just a person to connect with because his romantic life didn’t offer what he truly wanted. This all happens after Sherlock gets a text from Irene. To Sherlock, she filled the exact same role. She was a woman who smiled, who he would only text, who Sherlock connected with because what he truly wanted wasn’t something he could ever have.
The only person for Sherlock is John. The only person for John is Sherlock. And after all of this pain, they both know it.