This has been an issue across multiple Windows iterations of Notepad: the undo function, more often than not, doesn't undo the last X actions/characters, rather, it wipes the entire notepad of everything. It's a binary keep-precisely-what-you-have-now or start-fresh-with-nothing.
However, occasionally it doesn't go all the way back to a blank Notepad, and it'll undo some amount of input without wiping it all, but I don't know what the delimiter is that triggers the next undo-level monitoring.