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.
This commit is contained in:
Dan Stillman 2012-04-17 15:42:15 -04:00
parent 512ae575fa
commit 5275dafbc9
4 changed files with 26 additions and 30 deletions

View file

@ -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>

View file

@ -330,6 +330,14 @@
</body>
</method>
<method name="clearUndo">
<body>
<![CDATA[
this._editor.undoManager.clear();
]]>
</body>
</method>
<field name="_loaded"/>
<method name="_load">
<body>

View file

@ -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();
}

View file

@ -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) {