Fix being unable to place the cursor in between bubbles in the citation dialog

Regression in Fx60
This commit is contained in:
Adomas Venčkauskas 2019-12-23 13:25:00 +02:00
parent bfceb10e03
commit 5a1e329618

View file

@ -124,9 +124,10 @@ var Zotero_QuickFormat = new function () {
if(Zotero.isMac || Zotero.isWin) { if(Zotero.isMac || Zotero.isWin) {
referencePanel.setAttribute("noautohide", true); referencePanel.setAttribute("noautohide", true);
} }
} else if(event.target === qfi.contentDocument) { } else if (event.target === qfi.contentDocument) {
qfiWindow = qfi.contentWindow; qfiWindow = qfi.contentWindow;
qfiDocument = qfi.contentDocument; qfiDocument = qfi.contentDocument;
qfb.addEventListener("click", _onQuickSearchClick, false);
qfb.addEventListener("keypress", _onQuickSearchKeyPress, false); qfb.addEventListener("keypress", _onQuickSearchKeyPress, false);
qfe = qfiDocument.getElementById("quick-format-editor"); qfe = qfiDocument.getElementById("quick-format-editor");
qfe.addEventListener("drop", _onBubbleDrop, false); qfe.addEventListener("drop", _onBubbleDrop, false);
@ -138,7 +139,7 @@ var Zotero_QuickFormat = new function () {
* Initialize add citation dialog * Initialize add citation dialog
*/ */
this.onLoad = function(event) { this.onLoad = function(event) {
if(event.target !== document) return; if (event.target !== document) return;
// make sure we are visible // make sure we are visible
window.setTimeout(function() { window.setTimeout(function() {
window.resizeTo(window.outerWidth, qfb.clientHeight); window.resizeTo(window.outerWidth, qfb.clientHeight);
@ -236,9 +237,11 @@ var Zotero_QuickFormat = new function () {
// add to previous cite // add to previous cite
var node = _getCurrentEditorTextNode(); var node = _getCurrentEditorTextNode();
var prevNode = node.previousSibling; var prevNode = node.previousSibling;
if(prevNode && prevNode.citationItem && prevNode.citationItem.locator) { let citationItem = JSON.parse(prevNode && prevNode.dataset.citationItem || "{}");
prevNode.citationItem.locator += str; if (citationItem.locator) {
prevNode.textContent = _buildBubbleString(prevNode.citationItem); citationItem.locator += str;
prevNode.dataset.citationItem = JSON.stringify(citationItem);
prevNode.textContent = _buildBubbleString(citationItem);
node.nodeValue = ""; node.nodeValue = "";
_clearEntryList(); _clearEntryList();
return; return;
@ -253,9 +256,11 @@ var Zotero_QuickFormat = new function () {
// add to previous cite // add to previous cite
var node = _getCurrentEditorTextNode(); var node = _getCurrentEditorTextNode();
var prevNode = node.previousSibling; var prevNode = node.previousSibling;
let citationItem = JSON.parse(prevNode && prevNode.dataset.citationItem || "{}");
if(prevNode && prevNode.citationItem) { if(prevNode && prevNode.citationItem) {
prevNode.citationItem.locator = m[2]; citationItem.locator = m[2];
prevNode.textContent = _buildBubbleString(prevNode.citationItem); prevNode.dataset.citationItem = JSON.stringify(citationItem);
prevNode.textContent = _buildBubbleString(citationItem);
node.nodeValue = ""; node.nodeValue = "";
_clearEntryList(); _clearEntryList();
return; return;
@ -695,7 +700,7 @@ var Zotero_QuickFormat = new function () {
bubble.textContent = str; bubble.textContent = str;
bubble.addEventListener("click", _onBubbleClick, false); bubble.addEventListener("click", _onBubbleClick, false);
bubble.addEventListener("dragstart", _onBubbleDrag, false); bubble.addEventListener("dragstart", _onBubbleDrag, false);
bubble.citationItem = citationItem; bubble.dataset.citationItem = JSON.stringify(citationItem);
if(nextNode && nextNode instanceof Range) { if(nextNode && nextNode instanceof Range) {
nextNode.insertNode(bubble); nextNode.insertNode(bubble);
} else { } else {
@ -924,8 +929,10 @@ var Zotero_QuickFormat = new function () {
function _updateCitationObject() { function _updateCitationObject() {
var nodes = qfe.childNodes; var nodes = qfe.childNodes;
io.citation.citationItems = []; io.citation.citationItems = [];
for(var i=0, n=nodes.length; i<n; i++) { for (let node of nodes) {
if(nodes[i].citationItem) io.citation.citationItems.push(nodes[i].citationItem); if (node.dataset && node.dataset.citationItem) {
io.citation.citationItems.push(JSON.parse(node.dataset.citationItem));
}
} }
if(io.sortable) { if(io.sortable) {
@ -978,10 +985,11 @@ var Zotero_QuickFormat = new function () {
*/ */
function _showCitationProperties(target) { function _showCitationProperties(target) {
panelRefersToBubble = target; panelRefersToBubble = target;
panelPrefix.value = target.citationItem["prefix"] ? target.citationItem["prefix"] : ""; let citationItem = JSON.parse(target.dataset.citationItem);
panelSuffix.value = target.citationItem["suffix"] ? target.citationItem["suffix"] : ""; panelPrefix.value = citationItem["prefix"] ? citationItem["prefix"] : "";
if(target.citationItem["label"]) { panelSuffix.value = citationItem["suffix"] ? citationItem["suffix"] : "";
var option = panelLocatorLabel.getElementsByAttribute("value", target.citationItem["label"]); if(citationItem["label"]) {
var option = panelLocatorLabel.getElementsByAttribute("value", citationItem["label"]);
if(option.length) { if(option.length) {
panelLocatorLabel.selectedItem = option[0]; panelLocatorLabel.selectedItem = option[0];
} else { } else {
@ -990,12 +998,10 @@ var Zotero_QuickFormat = new function () {
} else { } else {
panelLocatorLabel.selectedIndex = 0; panelLocatorLabel.selectedIndex = 0;
} }
panelLocator.value = target.citationItem["locator"] ? target.citationItem["locator"] : ""; panelLocator.value = citationItem["locator"] ? citationItem["locator"] : "";
panelSuppressAuthor.checked = !!target.citationItem["suppress-author"]; panelSuppressAuthor.checked = !!citationItem["suppress-author"];
Zotero.Cite.getItem(panelRefersToBubble.citationItem.id).key; var item = Zotero.Cite.getItem(citationItem.id);
var item = Zotero.Cite.getItem(target.citationItem.id);
document.getElementById("citation-properties-title").textContent = item.getDisplayTitle(); document.getElementById("citation-properties-title").textContent = item.getDisplayTitle();
while(panelInfo.hasChildNodes()) panelInfo.removeChild(panelInfo.firstChild); while(panelInfo.hasChildNodes()) panelInfo.removeChild(panelInfo.firstChild);
_buildItemDescription(item, panelInfo); _buildItemDescription(item, panelInfo);
@ -1074,14 +1080,14 @@ var Zotero_QuickFormat = new function () {
// Check whether the bubble is selected // Check whether the bubble is selected
// Not sure whether this ever happens anymore // Not sure whether this ever happens anymore
var container = range.startContainer; var container = range.startContainer;
if(container !== qfe) { if (container !== qfe) {
if(container.citationItem) { if (container.dataset && container.dataset.citationItem) {
return container; return container;
} else if(container.nodeType === Node.TEXT_NODE && container.wholeText == "") { } else if (container.nodeType === Node.TEXT_NODE && container.wholeText == "") {
if(container.parentNode === qfe) { if (container.parentNode === qfe) {
var node = container; var node = container;
while((node = container.previousSibling)) { while (node = container.previousSibling) {
if(node.citationItem) { if (node.dataset.citationItem) {
return node; return node;
} }
} }
@ -1094,7 +1100,7 @@ var Zotero_QuickFormat = new function () {
var offset = range.startOffset, var offset = range.startOffset,
childNodes = qfe.childNodes, childNodes = qfe.childNodes,
node = childNodes[offset-(right ? 0 : 1)]; node = childNodes[offset-(right ? 0 : 1)];
if(node && node.citationItem) return node; if (node && node.dataset.citationItem) return node;
return null; return null;
} }
@ -1119,6 +1125,22 @@ var Zotero_QuickFormat = new function () {
}); });
} }
async function _onQuickSearchClick(event) {
if (qfGuidance) qfGuidance.hide();
let bubble = _getSelectedBubble(false);
if (bubble) {
event.preventDefault();
var nodeRange = qfiDocument.createRange();
nodeRange.selectNode(bubble);
nodeRange.collapse(false);
var selection = qfiWindow.getSelection();
selection.removeAllRanges();
selection.addRange(nodeRange);
}
}
/** /**
* Handle return or escape * Handle return or escape
*/ */
@ -1228,10 +1250,10 @@ var Zotero_QuickFormat = new function () {
* Get index of bubble in citations * Get index of bubble in citations
*/ */
function _getBubbleIndex(bubble) { function _getBubbleIndex(bubble) {
var nodes = qfe.childNodes, oldPosition = -1, index = 0; var nodes = qfe.childNodes, index = 0;
for(var i=0, n=nodes.length; i<n; i++) { for (let node of nodes) {
if(nodes[i].citationItem) { if (node.dataset.citationItem) {
if(nodes[i] == bubble) return index; if (node == bubble) return index;
index++; index++;
} }
} }
@ -1293,32 +1315,34 @@ var Zotero_QuickFormat = new function () {
* Handle changes to citation properties * Handle changes to citation properties
*/ */
this.onCitationPropertiesChanged = function(event) { this.onCitationPropertiesChanged = function(event) {
let citationItem = JSON.parse(panelRefersToBubble.dataset.citationItem || "{}");
if(panelPrefix.value) { if(panelPrefix.value) {
panelRefersToBubble.citationItem["prefix"] = panelPrefix.value; citationItem["prefix"] = panelPrefix.value;
} else { } else {
delete panelRefersToBubble.citationItem["prefix"]; delete citationItem["prefix"];
} }
if(panelSuffix.value) { if(panelSuffix.value) {
panelRefersToBubble.citationItem["suffix"] = panelSuffix.value; citationItem["suffix"] = panelSuffix.value;
} else { } else {
delete panelRefersToBubble.citationItem["suffix"]; delete citationItem["suffix"];
} }
if(panelLocatorLabel.selectedIndex !== 0) { if(panelLocatorLabel.selectedIndex !== 0) {
panelRefersToBubble.citationItem["label"] = panelLocatorLabel.selectedItem.value; citationItem["label"] = panelLocatorLabel.selectedItem.value;
} else { } else {
delete panelRefersToBubble.citationItem["label"]; delete citationItem["label"];
} }
if(panelLocator.value) { if(panelLocator.value) {
panelRefersToBubble.citationItem["locator"] = panelLocator.value; citationItem["locator"] = panelLocator.value;
} else { } else {
delete panelRefersToBubble.citationItem["locator"]; delete citationItem["locator"];
} }
if(panelSuppressAuthor.checked) { if(panelSuppressAuthor.checked) {
panelRefersToBubble.citationItem["suppress-author"] = true; citationItem["suppress-author"] = true;
} else { } else {
delete panelRefersToBubble.citationItem["suppress-author"]; delete citationItem["suppress-author"];
} }
panelRefersToBubble.textContent = _buildBubbleString(panelRefersToBubble.citationItem); panelRefersToBubble.dataset.citationItem = JSON.stringify(citationItem);
panelRefersToBubble.textContent = _buildBubbleString(citationItem);
}; };
/** /**
@ -1366,7 +1390,8 @@ var Zotero_QuickFormat = new function () {
* Show an item in the library it came from * Show an item in the library it came from
*/ */
this.showInLibrary = async function (itemID) { this.showInLibrary = async function (itemID) {
var id = itemID || parseInt(panelRefersToBubble.citationItem.id); let citationItem = JSON.parse(panelRefersToBubble.dataset.citationItem || "{}");
var id = itemID || citationItem.id;
var pane = Zotero.getActiveZoteroPane(); var pane = Zotero.getActiveZoteroPane();
// Open main window if it's not open (Mac) // Open main window if it's not open (Mac)
if (!pane) { if (!pane) {