Skip to content

Commit

Permalink
Prevent Undo from clearing existing note
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dstillman committed Mar 2, 2018
1 parent bf122ad commit 724329d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
5 changes: 5 additions & 0 deletions chrome/content/zotero/bindings/styled-textbox.xml
Expand Up @@ -605,6 +605,7 @@
<![CDATA[
if (this._editor) {
this._editor.undoManager.clear();
this._editor.undoManager.add();
}
]]>
</body>
Expand Down Expand Up @@ -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 () {
Expand Down
16 changes: 1 addition & 15 deletions chrome/content/zotero/note.js
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 724329d

Please sign in to comment.