From 7f23533ee968de7101fd127148c887593a146980 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Mon, 4 Oct 2021 13:23:03 +0300 Subject: [PATCH] Automatically update citations when user opens a note --- chrome/content/zotero/bindings/noteeditor.xml | 7 ++++--- chrome/content/zotero/xpcom/editorInstance.js | 14 ++++++++++---- note-editor | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml index 24dde52693..0f99d5dbcb 100644 --- a/chrome/content/zotero/bindings/noteeditor.xml +++ b/chrome/content/zotero/bindings/noteeditor.xml @@ -91,7 +91,7 @@ return this._editorInstance; } - this.initEditor = async (state) => { + this.initEditor = async (state, reloaded) => { if (this._editorInstance) { this._editorInstance.uninit(); } @@ -106,6 +106,7 @@ await this._editorInstance.init({ state, item: this._item, + reloaded, iframeWindow: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-view').contentWindow, popup: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-menu'), onNavigate: this._navigateHandler, @@ -145,13 +146,13 @@ let state = extraData && extraData[id] && extraData[id].state; if (state) { if (extraData[id].noteEditorID !== this._editorInstance.instanceID) { - this.initEditor(state); + this.initEditor(state, true); } } else { let curValue = this.item.note; if (curValue !== this._lastHtmlValue) { - this.initEditor(); + this.initEditor(null, true); } } this._lastHtmlValue = this.item.note; diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 5ae95cda4e..2ede0c7252 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -56,6 +56,7 @@ class EditorInstance { this.onNavigate = options.onNavigate; // TODO: Consider to use only itemID instead of loaded item this._item = options.item; + this._reloaded = options.reloaded; this._viewMode = options.viewMode; this._readOnly = options.readOnly || this._isReadOnly(); this._disableUI = options.disableUI; @@ -170,7 +171,7 @@ class EditorInstance { let uris = items.map(x => Zotero.URI.getItemURI(x)).filter(x => x); let citationItemsList = this._citationItemsList .filter(ci => ci.uris && uris.some(uri => ci.uris.includes(uri))); - await this._updateCitationItems(citationItemsList); + await this._updateCitationItems(citationItemsList, true); } saveSync() { @@ -671,6 +672,7 @@ class EditorInstance { this._subscriptions.splice(this._subscriptions.findIndex(s => s.id === id), 1); return; } + // Called on note editor load case 'updateCitationItemsList': { let { list } = message; let newList = []; @@ -681,7 +683,11 @@ class EditorInstance { newList.push(item); } } - await this._updateCitationItems(newList); + // Force note saving only when note was opened by user and not by + // reload, otherwise it can result to sync carousel, if different + // clients have different citation item data and the same note is + // opened on both clients + await this._updateCitationItems(newList, !this._reloaded); this._citationItemsList = list; return; } @@ -756,7 +762,7 @@ class EditorInstance { } } - async _updateCitationItems(citationItemsList) { + async _updateCitationItems(citationItemsList, forceSaving) { let citationItems = []; for (let { uris } of citationItemsList) { let item = await Zotero.EditorInstance.getItemFromURIs(uris); @@ -766,7 +772,7 @@ class EditorInstance { } } if (citationItems.length) { - this._postMessage({ action: 'updateCitationItems', citationItems }); + this._postMessage({ action: 'updateCitationItems', citationItems, forceSaving }); } } diff --git a/note-editor b/note-editor index 263eec53a5..ed8d0b84b3 160000 --- a/note-editor +++ b/note-editor @@ -1 +1 @@ -Subproject commit 263eec53a5f0e8ab3960be9ea8d0db4ef19a4761 +Subproject commit ed8d0b84b3f16d66a75be11208ce5c8a3f3fc182