From f9e94d17b4ef41051ad51d5b0d339368ab2588d7 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Tue, 1 Oct 2024 16:14:37 -0500 Subject: [PATCH] Update positions of all feedback popovers when typing in a MathQuill input, Don't only update the popover corresponding to the input that is currently being typed in. This fixes the issue reported by @somiaj in https://github.com/openwebwork/pg/pull/1110#issuecomment-2380357222. --- htdocs/js/MathQuill/mqeditor.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/js/MathQuill/mqeditor.js b/htdocs/js/MathQuill/mqeditor.js index c2f589a3d..57336c231 100644 --- a/htdocs/js/MathQuill/mqeditor.js +++ b/htdocs/js/MathQuill/mqeditor.js @@ -37,7 +37,7 @@ if (input.classList.contains('partially-correct')) answerQuill.classList.add('partially-correct'); // Find the feedback button for this input if there is one on the page. - const feedbackBtn = Array.from(document.querySelectorAll(`button[data-answer-labels]`)).find((btn) => + answerQuill.feedbackBtn = Array.from(document.querySelectorAll(`button[data-answer-labels]`)).find((btn) => JSON.parse(btn.dataset.answerLabels).includes(answerLabel) ); @@ -269,8 +269,11 @@ answerQuill.latexInput.value = ''; } - // If the feedback popover is open, then update its position. - if (feedbackBtn) bootstrap.Popover.getInstance(feedbackBtn)?.update(); + // If any feedback popovers are open, then update their positions. + for (const quill of Object.keys(window.answerQuills)) { + if (window.answerQuills[quill].feedbackBtn) + bootstrap.Popover.getInstance(window.answerQuills[quill].feedbackBtn)?.update(); + } }; input.after(answerQuill);