qf: fix prepending multiple inputs to the editor

Fixes: #4041
This commit is contained in:
Bogdan Abaev 2024-04-23 19:27:22 -04:00 committed by Adomas Ven
parent 12b6645a1f
commit fbfe4b2dfa

View file

@ -1717,9 +1717,9 @@ var Zotero_QuickFormat = new function () {
let { lastBubble, startOfTheLine } = getLastBubbleBeforePoint(clickX, clickY); let { lastBubble, startOfTheLine } = getLastBubbleBeforePoint(clickX, clickY);
// If click happened right before another input, focus that input // If click happened right before another input, focus that input
// instead of adding another one. There may be a br node on the way, so we have to check // instead of adding another one. There may be a br node on the way, so we have to check
// more than just the next node. // more than just the next node. If there is no lastBubble and there is an input
if (lastBubble) { // at the start of the editor, focus it.
let nextNode = lastBubble.nextElementSibling; let nextNode = lastBubble ? lastBubble.nextElementSibling : editor.firstChild;
while (nextNode && !nextNode.classList.contains("bubble")) { while (nextNode && !nextNode.classList.contains("bubble")) {
if (isInput(nextNode)) { if (isInput(nextNode)) {
nextNode.focus(); nextNode.focus();
@ -1727,7 +1727,6 @@ var Zotero_QuickFormat = new function () {
} }
nextNode = nextNode.nextElementSibling; nextNode = nextNode.nextElementSibling;
} }
}
let newInput = _createInputField(); let newInput = _createInputField();
let currentInput = _getCurrentInput() || _lastFocusedInput; let currentInput = _getCurrentInput() || _lastFocusedInput;
// If there is a current input, delete it here. // If there is a current input, delete it here.