Automatically update citations when user opens a note
This commit is contained in:
parent
3b84e29c9e
commit
7f23533ee9
3 changed files with 15 additions and 8 deletions
|
@ -91,7 +91,7 @@
|
||||||
return this._editorInstance;
|
return this._editorInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.initEditor = async (state) => {
|
this.initEditor = async (state, reloaded) => {
|
||||||
if (this._editorInstance) {
|
if (this._editorInstance) {
|
||||||
this._editorInstance.uninit();
|
this._editorInstance.uninit();
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,7 @@
|
||||||
await this._editorInstance.init({
|
await this._editorInstance.init({
|
||||||
state,
|
state,
|
||||||
item: this._item,
|
item: this._item,
|
||||||
|
reloaded,
|
||||||
iframeWindow: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-view').contentWindow,
|
iframeWindow: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-view').contentWindow,
|
||||||
popup: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-menu'),
|
popup: document.getAnonymousElementByAttribute(this, 'anonid', 'editor-menu'),
|
||||||
onNavigate: this._navigateHandler,
|
onNavigate: this._navigateHandler,
|
||||||
|
@ -145,13 +146,13 @@
|
||||||
let state = extraData && extraData[id] && extraData[id].state;
|
let state = extraData && extraData[id] && extraData[id].state;
|
||||||
if (state) {
|
if (state) {
|
||||||
if (extraData[id].noteEditorID !== this._editorInstance.instanceID) {
|
if (extraData[id].noteEditorID !== this._editorInstance.instanceID) {
|
||||||
this.initEditor(state);
|
this.initEditor(state, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let curValue = this.item.note;
|
let curValue = this.item.note;
|
||||||
if (curValue !== this._lastHtmlValue) {
|
if (curValue !== this._lastHtmlValue) {
|
||||||
this.initEditor();
|
this.initEditor(null, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._lastHtmlValue = this.item.note;
|
this._lastHtmlValue = this.item.note;
|
||||||
|
|
|
@ -56,6 +56,7 @@ class EditorInstance {
|
||||||
this.onNavigate = options.onNavigate;
|
this.onNavigate = options.onNavigate;
|
||||||
// TODO: Consider to use only itemID instead of loaded item
|
// TODO: Consider to use only itemID instead of loaded item
|
||||||
this._item = options.item;
|
this._item = options.item;
|
||||||
|
this._reloaded = options.reloaded;
|
||||||
this._viewMode = options.viewMode;
|
this._viewMode = options.viewMode;
|
||||||
this._readOnly = options.readOnly || this._isReadOnly();
|
this._readOnly = options.readOnly || this._isReadOnly();
|
||||||
this._disableUI = options.disableUI;
|
this._disableUI = options.disableUI;
|
||||||
|
@ -170,7 +171,7 @@ class EditorInstance {
|
||||||
let uris = items.map(x => Zotero.URI.getItemURI(x)).filter(x => x);
|
let uris = items.map(x => Zotero.URI.getItemURI(x)).filter(x => x);
|
||||||
let citationItemsList = this._citationItemsList
|
let citationItemsList = this._citationItemsList
|
||||||
.filter(ci => ci.uris && uris.some(uri => ci.uris.includes(uri)));
|
.filter(ci => ci.uris && uris.some(uri => ci.uris.includes(uri)));
|
||||||
await this._updateCitationItems(citationItemsList);
|
await this._updateCitationItems(citationItemsList, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveSync() {
|
saveSync() {
|
||||||
|
@ -671,6 +672,7 @@ class EditorInstance {
|
||||||
this._subscriptions.splice(this._subscriptions.findIndex(s => s.id === id), 1);
|
this._subscriptions.splice(this._subscriptions.findIndex(s => s.id === id), 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Called on note editor load
|
||||||
case 'updateCitationItemsList': {
|
case 'updateCitationItemsList': {
|
||||||
let { list } = message;
|
let { list } = message;
|
||||||
let newList = [];
|
let newList = [];
|
||||||
|
@ -681,7 +683,11 @@ class EditorInstance {
|
||||||
newList.push(item);
|
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;
|
this._citationItemsList = list;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -756,7 +762,7 @@ class EditorInstance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _updateCitationItems(citationItemsList) {
|
async _updateCitationItems(citationItemsList, forceSaving) {
|
||||||
let citationItems = [];
|
let citationItems = [];
|
||||||
for (let { uris } of citationItemsList) {
|
for (let { uris } of citationItemsList) {
|
||||||
let item = await Zotero.EditorInstance.getItemFromURIs(uris);
|
let item = await Zotero.EditorInstance.getItemFromURIs(uris);
|
||||||
|
@ -766,7 +772,7 @@ class EditorInstance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (citationItems.length) {
|
if (citationItems.length) {
|
||||||
this._postMessage({ action: 'updateCitationItems', citationItems });
|
this._postMessage({ action: 'updateCitationItems', citationItems, forceSaving });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 263eec53a5f0e8ab3960be9ea8d0db4ef19a4761
|
Subproject commit ed8d0b84b3f16d66a75be11208ce5c8a3f3fc182
|
Loading…
Add table
Reference in a new issue