Specify note auto-sync timeout in save call, not in sync event listener
This will allow other operations to specify a longer timeout.
This commit is contained in:
parent
808b71832e
commit
9a47f74787
5 changed files with 30 additions and 13 deletions
|
@ -276,6 +276,7 @@
|
||||||
this.noteField.changed = false;
|
this.noteField.changed = false;
|
||||||
yield this.item.saveTx({
|
yield this.item.saveTx({
|
||||||
notifierData: {
|
notifierData: {
|
||||||
|
autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY,
|
||||||
noteEditorID: this.instanceID
|
noteEditorID: this.instanceID
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -293,7 +294,11 @@
|
||||||
item.parentKey = this.parentItem.key;
|
item.parentKey = this.parentItem.key;
|
||||||
}
|
}
|
||||||
if (this.saveOnEdit) {
|
if (this.saveOnEdit) {
|
||||||
var id = yield item.saveTx();
|
var id = yield item.saveTx({
|
||||||
|
notifierData: {
|
||||||
|
autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!this.parentItem && this.collection) {
|
if (!this.parentItem && this.collection) {
|
||||||
this.collection.addItem(id);
|
this.collection.addItem(id);
|
||||||
|
|
|
@ -25,13 +25,14 @@
|
||||||
|
|
||||||
|
|
||||||
Zotero.Notes = new function() {
|
Zotero.Notes = new function() {
|
||||||
this._editorInstances = [];
|
this.AUTO_SYNC_DELAY = 15;
|
||||||
|
|
||||||
this.__defineGetter__("MAX_TITLE_LENGTH", function() { return 120; });
|
this.__defineGetter__("MAX_TITLE_LENGTH", function() { return 120; });
|
||||||
this.__defineGetter__("defaultNote", function () { return '<div class="zotero-note znv1"></div>'; });
|
this.__defineGetter__("defaultNote", function () { return '<div class="zotero-note znv1"></div>'; });
|
||||||
this.__defineGetter__("notePrefix", function () { return '<div class="zotero-note znv1">'; });
|
this.__defineGetter__("notePrefix", function () { return '<div class="zotero-note znv1">'; });
|
||||||
this.__defineGetter__("noteSuffix", function () { return '</div>'; });
|
this.__defineGetter__("noteSuffix", function () { return '</div>'; });
|
||||||
|
|
||||||
|
this._editorInstances = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return first line (or first MAX_LENGTH characters) of note content
|
* Return first line (or first MAX_LENGTH characters) of note content
|
||||||
**/
|
**/
|
||||||
|
|
|
@ -808,6 +808,8 @@ class EditorInstance {
|
||||||
await this._item.save({
|
await this._item.save({
|
||||||
skipDateModifiedUpdate,
|
skipDateModifiedUpdate,
|
||||||
notifierData: {
|
notifierData: {
|
||||||
|
// Use a longer timeout to avoid repeated syncing during typing
|
||||||
|
autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY,
|
||||||
noteEditorID: this.instanceID,
|
noteEditorID: this.instanceID,
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
@ -826,7 +828,11 @@ class EditorInstance {
|
||||||
item.parentKey = this.parentItem.key;
|
item.parentKey = this.parentItem.key;
|
||||||
}
|
}
|
||||||
if (!this._disableSaving) {
|
if (!this._disableSaving) {
|
||||||
var id = await item.saveTx();
|
var id = await item.saveTx({
|
||||||
|
notifierData: {
|
||||||
|
autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY
|
||||||
|
}
|
||||||
|
});
|
||||||
if (!this.parentItem && this.collection) {
|
if (!this.parentItem && this.collection) {
|
||||||
this.collection.addItem(id);
|
this.collection.addItem(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,6 @@ Zotero.Sync.EventListeners.ChangeListener = new function () {
|
||||||
|
|
||||||
Zotero.Sync.EventListeners.AutoSyncListener = {
|
Zotero.Sync.EventListeners.AutoSyncListener = {
|
||||||
_editTimeout: 3,
|
_editTimeout: 3,
|
||||||
_noteEditTimeout: 15,
|
|
||||||
_observerID: null,
|
_observerID: null,
|
||||||
|
|
||||||
init: function () {
|
init: function () {
|
||||||
|
@ -168,13 +167,15 @@ Zotero.Sync.EventListeners.AutoSyncListener = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var noteEdit = false;
|
var autoSyncDelay = 0;
|
||||||
if (type == 'item' && (event == 'add' || event == 'modify' || event == 'index')) {
|
if (type == 'item') {
|
||||||
// Use a longer timeout for a single note edit, to avoid repeating syncing during typing
|
// Use a different timeout if specified (e.g., for note editing)
|
||||||
if (ids.length == 1 && (Zotero.Items.get(ids[0]) || {}).itemType == 'note') {
|
if (extraData[ids[0]] && extraData[ids[0]].autoSyncDelay) {
|
||||||
noteEdit = true;
|
autoSyncDelay = Math.max(autoSyncDelay, extraData[ids[0]].autoSyncDelay);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
// Check whether file syncing or full-text syncing are necessary
|
||||||
|
if (event == 'add' || event == 'modify' || event == 'index') {
|
||||||
for (let id of ids) {
|
for (let id of ids) {
|
||||||
let item = Zotero.Items.get(id);
|
let item = Zotero.Items.get(id);
|
||||||
if (!item) continue;
|
if (!item) continue;
|
||||||
|
@ -189,7 +190,7 @@ Zotero.Sync.EventListeners.AutoSyncListener = {
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Sync.Runner.setSyncTimeout(
|
Zotero.Sync.Runner.setSyncTimeout(
|
||||||
noteEdit ? this._noteEditTimeout : this._editTimeout,
|
autoSyncDelay || this._editTimeout,
|
||||||
false,
|
false,
|
||||||
{
|
{
|
||||||
libraries: libraries.map(library => library.libraryID),
|
libraries: libraries.map(library => library.libraryID),
|
||||||
|
|
|
@ -3492,7 +3492,11 @@ var ZoteroPane = new function()
|
||||||
else if (this.collectionsView.selectedTreeRow.isCollection()) {
|
else if (this.collectionsView.selectedTreeRow.isCollection()) {
|
||||||
item.addToCollection(this.collectionsView.selectedTreeRow.ref.id);
|
item.addToCollection(this.collectionsView.selectedTreeRow.ref.id);
|
||||||
}
|
}
|
||||||
var itemID = yield item.saveTx();
|
var itemID = yield item.saveTx({
|
||||||
|
notifierData: {
|
||||||
|
autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
yield this.selectItem(itemID);
|
yield this.selectItem(itemID);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue