Avoid locator detection on paste in citation dialog. Closes #2856

Locators will get detected if there is additional typing or editing
after the paste
This commit is contained in:
Adomas Venčkauskas 2022-11-22 15:54:28 +02:00
parent 29006c556d
commit deb5d1cd27

View file

@ -37,7 +37,8 @@ var Zotero_QuickFormat = new function () {
keepSorted, showEditor, referencePanel, referenceBox, referenceHeight = 0, keepSorted, showEditor, referencePanel, referenceBox, referenceHeight = 0,
separatorHeight = 0, currentLocator, currentLocatorLabel, currentSearchTime, dragging, separatorHeight = 0, currentLocator, currentLocatorLabel, currentSearchTime, dragging,
panel, panelPrefix, panelSuffix, panelSuppressAuthor, panelLocatorLabel, panelLocator, panel, panelPrefix, panelSuffix, panelSuppressAuthor, panelLocatorLabel, panelLocator,
panelLibraryLink, panelInfo, panelRefersToBubble, panelFrameHeight = 0, accepted = false; panelLibraryLink, panelInfo, panelRefersToBubble, panelFrameHeight = 0, accepted = false,
isPaste = false;
var locatorLocked = true; var locatorLocked = true;
var locatorNode = null; var locatorNode = null;
var _searchPromise; var _searchPromise;
@ -215,11 +216,11 @@ var Zotero_QuickFormat = new function () {
// Range could be referenced to the body element // Range could be referenced to the body element
if(node === qfe) { if(node === qfe) {
var offset = range.startOffset; for (let i = qfe.childNodes.length - 1; i >= 0; i--) {
if(offset !== range.endOffset) return false; node = qfe.childNodes[i];
node = qfe.childNodes[Math.min(qfe.childNodes.length-1, offset)];
if(node.nodeType === Node.TEXT_NODE) return node; if(node.nodeType === Node.TEXT_NODE) return node;
} }
}
return false; return false;
} }
@ -238,7 +239,7 @@ var Zotero_QuickFormat = new function () {
* @return {String} str without locator * @return {String} str without locator
*/ */
function _updateLocator(str) { function _updateLocator(str) {
m = locatorRe.exec(str); m = !isPaste && locatorRe.exec(str);
if(m && (m[1] || m[2] || m[3].length !== 4) && m.index > 0) { if(m && (m[1] || m[2] || m[3].length !== 4) && m.index > 0) {
currentLocator = m[3]; currentLocator = m[3];
str = str.substr(0, m.index)+str.substring(m.index+m[0].length); str = str.substr(0, m.index)+str.substring(m.index+m[0].length);
@ -866,6 +867,7 @@ var Zotero_QuickFormat = new function () {
// handling to maintain the correct locator node in // handling to maintain the correct locator node in
// _showCitation() // _showCitation()
var bubble = locatorNode = _insertBubble(citationItem, node); var bubble = locatorNode = _insertBubble(citationItem, node);
isPaste = false;
_clearEntryList(); _clearEntryList();
yield _previewAndSort(); yield _previewAndSort();
_refocusQfe(); _refocusQfe();
@ -1352,6 +1354,7 @@ var Zotero_QuickFormat = new function () {
event.preventDefault(); event.preventDefault();
} }
} else { } else {
isPaste = false;
_resetSearchTimer(); _resetSearchTimer();
} }
}); });