Opened 5 years ago
Closed 5 years ago
#1887 closed defect (fixed)
Retrieving editor.value in Zotero_Citation_Dialog._updatePreview() fails
| Reported by: | fbennett | Owned by: | simon |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | interface | Version: | 2.1 |
| Keywords: | Cc: | fbennett |
Description
By the code in Zotero_Citation_Dialog.accept() [in addCitationDialog.js], it looks as though citations are meant to be dynamic if _originalHTML (actually an RTF string) matches the value property of the editor node. This test always fails, however.
_originalHTML is set by setting the preview string in editor.value, and immediately reading it back into _originalHTML. The set attempt triggers a build of the editor, which runs asynchronously and takes some time to complete. A try/catch around the read attempt shows that JS crashes at that point because the editor is not yet available.
For reference, interesting parts of the code seem to be around line 626 of addCitationDialog.js, and the load() function starting around line 325 in styled-textbox.xml.
Attachments (1)
Change History (9)
comment:1 Changed 5 years ago by fbennett
comment:2 Changed 5 years ago by dstillman
- Owner changed from dstillman to simon
- Status changed from new to assigned
comment:3 Changed 5 years ago by fbennett
I've updated the patch. It contains some debug statements flagged with "YYY" for convenience in review.
The main substantive changes with the revision are
- to mark a cite as non-custom if _originalHTML evaluates false; and
- to set an empty string in citation.properties.custom if the citation analyzes as non-custom.
With these changes, it seems very smooth. If a cite is customized, the customization sticks, with the editor window showing. If a customized citation is edited to be exactly the same as the generated form, it will become dynamic, and the editor window will come up closed on the next edit.
comment:4 Changed 5 years ago by simon
That patch looks the same as the previous one. Can you re-upload?
Changed 5 years ago by fbennett
comment:5 Changed 5 years ago by fbennett
Sorry, I uploaded from the wrong working directory. It's refreshed now.
comment:6 Changed 5 years ago by simon
I think r10290 should fix things. The reason for the pattern
editor.value = io.previewFunction(); _originalHTML = editor.value;
is that _originalHTML (which is actually RTF) is not guaranteed to round-trip back to the same thing it started as. r10290 sets _originalHTML correctly in the case that the editor is not yet ready.
(FWIW, the editor isn't included or necessary in the Quick Format dialog; in 3.0, you can just modify the citation in place.)
comment:7 Changed 5 years ago by fbennett
Very nice!
One small nit: when a citation is edited in place and then confirmed on refresh, a subsequent edit via the Classic View opens with the editor closed, and the changes are lost if Show Editor is clicked. That might cause confusion if two people with different habits are working on the same document.
comment:8 Changed 5 years ago by simon
- Resolution set to fixed
- Status changed from assigned to closed
Thanks for noticing. I've created #1888 to handle that issue.
With a little more poking around, I discovered that the problem was a combination of the _originalHTML setting issue, plus misformatting in the custom string set in the field. The attached patch against the trunk seems to get things working smoothly.
The patch also addresses an issue with using Show Editor on the first (only?) citation in a document, which I've seen mentioned in the forums, but can't seem to locate.