mirror of
https://github.com/zotero/zotero.git
synced 2026-10-03 02:21:49 +00:00
Fix note editor hard refresh after saving note (#5640)
Fix note editor instances' editing state lost after saving
This commit is contained in:
parent
c60134e8f1
commit
ccfa109fcf
2 changed files with 48 additions and 2 deletions
|
|
@ -182,13 +182,15 @@
|
|||
let state = extraData && extraData[id] && extraData[id].state;
|
||||
if (state) {
|
||||
if (extraData[id].noteEditorID !== this._editorInstance.instanceID) {
|
||||
this.initEditor(state, true);
|
||||
let noteData = { state, html: this._item.note };
|
||||
this._editorInstance.applyIncrementalUpdate(noteData, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let curValue = this._item.note;
|
||||
if (curValue !== this._lastHtmlValue) {
|
||||
this.initEditor(null, true);
|
||||
let noteData = { html: curValue };
|
||||
this._editorInstance.applyIncrementalUpdate(noteData, true);
|
||||
}
|
||||
}
|
||||
this._lastHtmlValue = this._item.note;
|
||||
|
|
|
|||
|
|
@ -230,6 +230,25 @@ class EditorInstance {
|
|||
}
|
||||
}
|
||||
|
||||
async reinit(state = null) {
|
||||
let currentOptions = {
|
||||
state: state || this._state,
|
||||
item: this._item,
|
||||
reloaded: true,
|
||||
iframeWindow: this._iframeWindow,
|
||||
popup: this._popup,
|
||||
onNavigate: this.onNavigate,
|
||||
viewMode: this._viewMode,
|
||||
readOnly: this._readOnly,
|
||||
disableUI: this._disableUI,
|
||||
onReturn: this._onReturn,
|
||||
placeholder: this._placeholder
|
||||
};
|
||||
|
||||
await this.uninit();
|
||||
await this.init(currentOptions);
|
||||
}
|
||||
|
||||
focus() {
|
||||
this._postMessage({ action: 'focus' });
|
||||
}
|
||||
|
|
@ -283,6 +302,26 @@ class EditorInstance {
|
|||
this._postMessage({ action: 'insertHTML', pos: null, html });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply external changes incrementally instead of reinitializing the entire editor
|
||||
* @param {Object} noteData - The note data containing state and html
|
||||
* @param {Object} [noteData.state] - state object of editor
|
||||
* @param {String} noteData.html - html for fallback update
|
||||
* @param {boolean} preserveSelection - Whether to preserve the current selection
|
||||
*/
|
||||
applyIncrementalUpdate(noteData, preserveSelection = true) {
|
||||
if (this._readOnly || !this._iframeWindow) {
|
||||
this.reinit(noteData.state || null);
|
||||
return;
|
||||
}
|
||||
|
||||
this._postMessage({
|
||||
action: 'updateIncrementally',
|
||||
noteData,
|
||||
preserveSelection
|
||||
});
|
||||
}
|
||||
|
||||
_postMessage(message) {
|
||||
this._iframeWindow.postMessage({ instanceID: this.instanceID, message }, '*');
|
||||
|
|
@ -709,6 +748,11 @@ class EditorInstance {
|
|||
this._onReturn();
|
||||
return;
|
||||
}
|
||||
case 'incrementalUpdateFailed': {
|
||||
// Incremental update failed, do full reinitialize
|
||||
this.reinit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue