Is it necessary to reload the editor every time we change document key in the config i.e after every edit and save?

  • after I edit and save in the editor, I am updating the key, but this doesn’t update the editor. So I had to destroyEditor() and then reconnect again to make the updated key work but UX is bad as the editor refreshes on every save so I need a solution. The pseudo code on what I am doing currently:
  let docEditor;
        
	const connectEditor = () => {
		try {
			let editor = new DocsAPI.DocEditor(editorDivId, config);
			docEditor = editor;
			fixSize();
		} catch (error) {
			console.error(error);
		}
	};
        
       const reloadEditor = () => {
		if (docEditor) {
			docEditor.destroyEditor();
			docEditor = undefined;
		}
		connectEditor();
	};

       //some event triggered after document edit and save
       config.document.key = <some new key>
        //but only updating key in the config is not actually updating the key in the editor, 
        //unless I explicitly do
       reloadEditor()

Hello @bipana.shrestha ,
Yes, it is necessary to reinitialize document editor.

Hello @Farkhod, thanks for replying. Wanted to ask if docEditor.destroyEditor() is necessary? Or just connectEditor() will be enough after updating the key?

It does not matter, which way you are going to do this. You can even reload the webpage manually. The main point is to reinitialize the document editor.

@Farkhod The issue I have is when I am editing the doc, say if I am on page 3 and I edit and save then reinitialize the editor. But I lose my place in the editor i.e on page 3. How can I retain my place in the editor after reinitializing?

Hello,
You can do this by using “Bookmarks”.

https://helpcenter.onlyoffice.com/onlyoffice-editors/onlyoffice-document-editor/UsageInstructions/InsertBookmarks.aspx

https://api.onlyoffice.com/editors/actionlink

https://api.onlyoffice.com/editors/methods#setActionLink

But doesn’t this mean the editor needs to add bookmarks manually from the editor and we can’t do it for the editors on every edit and save i.e reinitialize. We cannot trigger the event onMakeActionLink unless the editor adds the bookmark from within the editor and therefore don’t have action_data to create the link . Here “we” means document manager @Farkhod

Hi,
If you want to open a document at a particular place, the only way to do it is via bookmarks and action links.