The formatting from SSMS is problematic. It has various forms, and this editor doesn’t handle it great. The best thing I’ve found is to paste, then highlight the code here and choose SQL Code at the bottom of the edit box. Even that sometimes doens’t work with strange mixes of CHR(10), CHR(13), and HTML tags, so I try to be careful. Overall, if you aren’t sure about the code, just paste it in.
Also, if it’s more than 5 minutes work, I often use CTRL+A, C a few times as I’m working to be sure I have a copy. Maybe paste in Notepad to save it.