commit 724329d94865acfc16bbd5665385d75de4dca371
parent bf122add81b39521c6613553099a87cd1186978f
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 1 Mar 2018 18:24:08 -0500
Prevent Undo from clearing existing note
When loading the first note of a session in the right-hand pane or when
loading a note in the separate window, if you made a change and then
pressed Undo twice (or maybe only once in some situations), it could
undo to empty (though you could usually Redo to restore it).
Diffstat:
2 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/chrome/content/zotero/bindings/styled-textbox.xml b/chrome/content/zotero/bindings/styled-textbox.xml
@@ -605,6 +605,7 @@
<![CDATA[
if (this._editor) {
this._editor.undoManager.clear();
+ this._editor.undoManager.add();
}
]]>
</body>
@@ -690,6 +691,10 @@
}
if (self._value) {
self.value = self._value;
+
+ // Prevent undoing to empty note after initialization
+ self._editor.undoManager.clear();
+ self._editor.undoManager.add();
}
if (self._focus) {
setTimeout(function () {
diff --git a/chrome/content/zotero/note.js b/chrome/content/zotero/note.js
@@ -43,18 +43,7 @@ async function onLoad() {
if (itemID) {
var ref = await Zotero.Items.getAsync(itemID);
-
- // 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.
- let clearUndo = noteEditor.item ? noteEditor.item.id != itemID : false;
-
noteEditor.item = ref;
-
- if (clearUndo) {
- noteEditor.clearUndo();
- }
-
document.title = ref.getNoteTitle();
}
else {
@@ -96,12 +85,9 @@ function onUnload() {
var NotifyCallback = {
notify: function(action, type, ids){
- if (noteEditor.item && ids.indexOf(noteEditor.item.id) != -1) {
- // If the document title hasn't yet been set, reset undo so
- // undoing to empty isn't possible
+ if (noteEditor.item && ids.includes(noteEditor.item.id)) {
var noteTitle = noteEditor.item.getNoteTitle();
if (!document.title && noteTitle != '') {
- noteEditor.clearUndo();
document.title = noteTitle;
}