Skip to content

Commit

Permalink
Instead of the previous hack, just focus the input before issuing the…
Browse files Browse the repository at this point in the history
… button command.
  • Loading branch information
drgrice1 committed Jan 10, 2025
1 parent 10ebf83 commit aa53648
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions htdocs/js/MathQuill/mqeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,11 @@
cfgOptions.handlers = {
// Disable the toolbar when a text block is entered.
textBlockEnter: () => {
if (answerQuill.toolbar) {
// This is a workaround for a Google Chrome oddity. For some reason, if a button is disabled, then
// when it loses focus, the relatedTarget in the focusout event is not set even though the
// relatedTarget is not the button at all, but where the focus is going. Firefox and Safari
// (apparently) still set the relatedTarget.
answerQuill.toolbar.preventRemove = true;
answerQuill.toolbar.querySelectorAll('button').forEach((button) => (button.disabled = true));
}
answerQuill.toolbar?.querySelectorAll('button').forEach((button) => (button.disabled = true));
},
// Re-enable the toolbar when a text block is exited.
textBlockExit: () => {
if (answerQuill.toolbar)
answerQuill.toolbar.querySelectorAll('button').forEach((button) => (button.disabled = false));
answerQuill.toolbar?.querySelectorAll('button').forEach((button) => (button.disabled = false));
}
};

Expand Down Expand Up @@ -355,12 +347,9 @@
(e.relatedTarget.closest('.quill-toolbar') ||
e.relatedTarget.classList.contains('symbol-button') ||
e.relatedTarget === answerQuill.textarea)) ||
(answerQuill.clearButton && e.relatedTarget === answerQuill.clearButton) ||
answerQuill.toolbar?.preventRemove
) {
if (answerQuill.toolbar) delete answerQuill.toolbar.preventRemove;
(answerQuill.clearButton && e.relatedTarget === answerQuill.clearButton)
)
return;
}

toolbarRemove();
});
Expand Down Expand Up @@ -400,8 +389,8 @@
answerQuill.toolbar.tooltips.push(new bootstrap.Tooltip(button, { placement: 'left' }));

button.addEventListener('click', () => {
answerQuill.mathField.cmd(button.dataset.latex);
answerQuill.textarea.focus();
answerQuill.mathField.cmd(button.dataset.latex);
});
}

Expand Down Expand Up @@ -566,8 +555,6 @@
});

answerQuill.textarea.addEventListener('focusout', (e) => {
if (answerQuill.toolbar) delete answerQuill.toolbar.preventRemove;

if (
!document.hasFocus() ||
(e.relatedTarget &&
Expand Down

0 comments on commit aa53648

Please sign in to comment.