diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js index 714b797b5..bf20e5678 100644 --- a/chrome/content/zotero/note.js +++ b/chrome/content/zotero/note.js @@ -45,7 +45,14 @@ function onLoad() if (itemID) { var ref = Zotero.Items.get(itemID); + + // Make sure Undo doesn't wipe out the note + if (!noteEditor.note || noteEditor.note.getID() != ref.getID()) { + noteEditor.id('noteField').editor.enableUndo(false); + } noteEditor.note = ref; + noteEditor.id('noteField').editor.enableUndo(true); + document.title = ref.getNoteTitle(); } else if (parentItemID) { @@ -72,9 +79,18 @@ function onUnload() var NotifyCallback = { notify: function(action, type, ids){ // DEBUG: why does this reset without checking the modified ids? - if (noteEditor.note){ + if (noteEditor.note) { noteEditor.note = noteEditor.note; - document.title = noteEditor.note.getNoteTitle(); + + // If the document title hasn't yet been set, reset undo so + // undoing to empty isn't possible + var noteTitle = noteEditor.note.getNoteTitle(); + if (!document.title && noteTitle != '') { + noteEditor.id('noteField').editor.enableUndo(false); + noteEditor.id('noteField').editor.enableUndo(true); + document.title = noteTitle; + } + // Update the window name (used for focusing) in case this is a new note window.name = 'zotero-note-' + noteEditor.note.getID(); } diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 7743ed636..98ce910a9 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -763,8 +763,18 @@ var ZoteroPane = new function() if(item.isNote()) { var noteEditor = document.getElementById('zotero-note-editor'); + + // If loading new or different note, disable undo while we repopulate the text field + // so Undo doesn't end up clearing the field. This also ensures that Undo doesn't + // undo content from another note into the current one. + if (!noteEditor.note || noteEditor.note.getID() != item.ref.getID()) { + noteEditor.id('noteField').editor.enableUndo(false); + } noteEditor.item = null; noteEditor.note = item.ref; + + noteEditor.id('noteField').editor.enableUndo(true); + document.getElementById('zotero-view-note-button').setAttribute('noteID',item.ref.getID()); if(item.ref.getSource()) {