This function will fix the crash of the cursor when you try to insert elements or add bookmarks.
1 2 3 4 5 6 7 8 9 | function fix_cursor(){ // get the cursor position stored by onCursorMove() var properties = PropertiesService.getScriptProperties(); var position = properties.getProperty("position"); if (position !== null){ // set cursor to last-stored position doc.setCursor(doc.newPosition(text, position)); } } |