Re-awakening an old topic. I have two suggestions here.
Calculate a cryptographic checksum before editing begins. When the user tries to exit, recalculate the checksum. If it has changed, we know the secure note was modified. If the user does edits then does more edits to undo those edits, there will not be a false alarm. Lastpass gives such false alarms and they are very annoying. Cryptographic checksums will reliably determine actual changes.
“Save or discard” prompts interrupt the flow of work. Instead, just do what the user seems to want to do, but save the modified apparently-discarded secure note (in encrypted form) in local storage, and let the user know in a mode-less fashion that the draft is still available. And provide a button (e.g., Undo, Retrieve Draft, etc.) to get back the saved draft. These drafts can be automatically purged after some timeout period. This strategy works nicely for email drafts and will work just as well for secure notes.