How to initialize the <zoteronoteeditor> instance correctly?

17 views
Skip to first unread message

XY Wong

unread,
Aug 15, 2022, 5:30:52 AMAug 15
to zotero-dev
Hi,

I'm using the Zotero 6 note editor in my plugin and it works very well.

One thing that bothers me is that the <zoteronoteeditor> instance seems to require to be initialized twice and the drop event listener requires an extra initialization.
Otherwise, the cursor will not be able to enter the note editor's table when clicked inside the table. I guess I'm not doing it right when initializing the note editor.



Here is my code for initialization the note editor instance:


Initialization steps:
  1. Select the zoteronoteeditor element by id in the workspace.xul;
  2. Check the  _initialized flag of the editor instance. If it is false, add the event listener following https://github.com/zotero/zotero/blob/85b0c9dbad942b19d1d8e2405a90b105907c5740/chrome/content/zotero/bindings/noteeditor.xml#L65. Otherwise the note editor will have duplicate lines when drag&drop inside the editor.
  3. Set note editor attributes:
    noteEditor.mode = "edit";
    noteEditor.viewMode = "library";
    noteEditor.parent = null;
    noteEditor.item = note;
  4. await noteEditor.initEditor();
  5. Re-init the editor if it's the first init since workspace.xul is open.

The code works well currently, though it's dirty. I believe there must be a correct way to initialize the note editor.
Thank you very much!
Reply all
Reply to author
Forward
0 new messages