www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 5275dafbc9f2c45fa052308c26d32b10423bfaa4
parent 512ae575fae9233e87eaad75b1735aede4df6369
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 17 Apr 2012 15:42:15 -0400

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.

Diffstat:
Mchrome/content/zotero/bindings/noteeditor.xml | 19+------------------
Mchrome/content/zotero/bindings/styled-textbox.xml | 8++++++++
Mchrome/content/zotero/note.js | 14+++++++++-----
Mchrome/content/zotero/zoteroPane.js | 13+++++++------
4 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml @@ -308,27 +308,10 @@ </body> </method> - <method name="disableUndo"> - <body> - <![CDATA[ - //this.noteField.editor.enableUndo(true); - ]]> - </body> - </method> - - <method name="enableUndo"> - <body> - <![CDATA[ - //this.noteField.editor.enableUndo(false); - ]]> - </body> - </method> - <method name="clearUndo"> <body> <![CDATA[ - this.disableUndo(); - this.enableUndo(); + this._id('noteField').clearUndo(); ]]> </body> </method> diff --git a/chrome/content/zotero/bindings/styled-textbox.xml b/chrome/content/zotero/bindings/styled-textbox.xml @@ -330,6 +330,14 @@ </body> </method> + <method name="clearUndo"> + <body> + <![CDATA[ + this._editor.undoManager.clear(); + ]]> + </body> + </method> + <field name="_loaded"/> <method name="_load"> <body> diff --git 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 @@ -1154,16 +1154,17 @@ var ZoteroPane = new function() var noteEditor = document.getElementById('zotero-note-editor'); noteEditor.mode = this.collectionsView.editable ? 'edit' : 'view'; + var clearUndo = noteEditor.item ? noteEditor.item.id != item.id : false; + + noteEditor.parent = null; + noteEditor.item = item; + // 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(); + if (clearUndo) { + noteEditor.clearUndo(); } - noteEditor.parent = null; - noteEditor.item = item; - - noteEditor.enableUndo(); var viewButton = document.getElementById('zotero-view-note-button'); if (this.collectionsView.editable) {