From 5275dafbc9f2c45fa052308c26d32b10423bfaa4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 17 Apr 2012 15:42:15 -0400 Subject: [PATCH] Clear undo history when switching notes This prevents notes from being overwritten with each other's contents. This used to work right, but it was broken with the switch to rich-text notes. --- chrome/content/zotero/bindings/noteeditor.xml | 19 +------------------ .../zotero/bindings/styled-textbox.xml | 8 ++++++++ chrome/content/zotero/note.js | 14 +++++++++----- chrome/content/zotero/zoteroPane.js | 15 ++++++++------- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml index 6929f9fcd0..32308e9dec 100644 --- a/chrome/content/zotero/bindings/noteeditor.xml +++ b/chrome/content/zotero/bindings/noteeditor.xml @@ -308,27 +308,10 @@ - - - - - - - - - - - - diff --git a/chrome/content/zotero/bindings/styled-textbox.xml b/chrome/content/zotero/bindings/styled-textbox.xml index 68fe168c98..585d52ca79 100644 --- a/chrome/content/zotero/bindings/styled-textbox.xml +++ b/chrome/content/zotero/bindings/styled-textbox.xml @@ -330,6 +330,14 @@ + + + + + + diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js index eb5a86cf4a..b3972aa834 100644 --- a/chrome/content/zotero/note.js +++ b/chrome/content/zotero/note.js @@ -49,12 +49,16 @@ function onLoad() { if (itemID) { var ref = Zotero.Items.get(itemID); - // Make sure Undo doesn't wipe out the note - if (!noteEditor.item || noteEditor.item.id != ref.id) { - noteEditor.disableUndo(); - } + var clearUndo = noteEditor.item ? noteEditor.item.id != ref.id : false; + noteEditor.item = ref; - noteEditor.enableUndo(); + + // 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 (clearUndo) { + noteEditor.clearUndo(); + } document.title = ref.getNoteTitle(); } diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 97f125244f..9a6d8c00b2 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -1154,16 +1154,17 @@ var ZoteroPane = new function() var noteEditor = document.getElementById('zotero-note-editor'); noteEditor.mode = this.collectionsView.editable ? 'edit' : 'view'; - // 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.item || noteEditor.item.id != item.id) { - noteEditor.disableUndo(); - } + var clearUndo = noteEditor.item ? noteEditor.item.id != item.id : false; + noteEditor.parent = null; noteEditor.item = item; - noteEditor.enableUndo(); + // 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 (clearUndo) { + noteEditor.clearUndo(); + } var viewButton = document.getElementById('zotero-view-note-button'); if (this.collectionsView.editable) {