refactoring annotation.js for saving notes when typing is finished and when text is pasted