Improve citation dialog locator experience with locator locking. Closes #1776

This commit is contained in:
Adomas Venčkauskas 2020-01-16 10:35:09 +02:00
parent d597f6a6c7
commit c6961b26e4

View file

@ -38,6 +38,7 @@ var Zotero_QuickFormat = new function () {
separatorHeight = 0, currentLocator, currentLocatorLabel, currentSearchTime, dragging,
panel, panelPrefix, panelSuffix, panelSuppressAuthor, panelLocatorLabel, panelLocator,
panelLibraryLink, panelInfo, panelRefersToBubble, panelFrameHeight = 0, accepted = false;
var locatorLocked = false;
var _searchPromise;
const SEARCH_TIMEOUT = 250;
@ -220,6 +221,9 @@ var Zotero_QuickFormat = new function () {
*/
var _quickFormat = Zotero.Promise.coroutine(function* () {
var str = _getEditorContent();
if (str.match(/\s$/)) {
locatorLocked = true;
}
var haveConditions = false;
const etAl = " et al.";
@ -233,12 +237,15 @@ var Zotero_QuickFormat = new function () {
currentLocatorLabel = false;
// check for adding a number onto a previous page number
if(numRe.test(str)) {
if(!locatorLocked && numRe.test(str)) {
// add to previous cite
var node = _getCurrentEditorTextNode();
var prevNode = node.previousSibling;
let citationItem = JSON.parse(prevNode && prevNode.dataset.citationItem || "null");
if (citationItem && citationItem.locator) {
if (citationItem) {
if (!("locator" in citationItem)) {
citationItem.locator = "";
}
citationItem.locator += str;
prevNode.dataset.citationItem = JSON.stringify(citationItem);
prevNode.textContent = _buildBubbleString(citationItem);
@ -263,6 +270,7 @@ var Zotero_QuickFormat = new function () {
prevNode.textContent = _buildBubbleString(citationItem);
node.nodeValue = "";
_clearEntryList();
locatorLocked = false;
return;
}
}
@ -774,6 +782,7 @@ var Zotero_QuickFormat = new function () {
citationItem["label"] = currentLocatorLabel;
}
}
locatorLocked = "locator" in citationItem;
// get next node and clear this one
var node = _getCurrentEditorTextNode();
@ -1342,6 +1351,7 @@ var Zotero_QuickFormat = new function () {
} else {
delete citationItem["suppress-author"];
}
locatorLocked = "locator" in citationItem;
panelRefersToBubble.dataset.citationItem = JSON.stringify(citationItem);
panelRefersToBubble.textContent = _buildBubbleString(citationItem);
};