Skip to content

Commit

Permalink
Allow having non commands as button values (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed2m authored May 4, 2021
1 parent d67b277 commit 16df556
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
type="checkbox"
class="option"
data-name="operators"
data-value='[["\\pm","\\pm"],["\\sqrt{x}","\\sqrt"],["\\sqrt[n]{x}","\\nthroot"],["\\frac{x}{y}","\\frac"],
["\\sum^{s}_{x}{d}", "\\sum"],["\\prod^{s}_{x}{d}", "\\prod"],["\\coprod^{s}_{x}{d}", "\\coprod"],
["\\int^{s}_{x}{d}", "\\int"],["\\binom{n}{k}", "\\binom"]]'>
data-value='[["\\pm","\\pm"],["\\sqrt{x}","\\sqrt"],["\\sqrt[3]{x}","\\sqrt[3]{}"],["\\sqrt[n]{x}","\\nthroot"],
["\\frac{x}{y}","\\frac"],["\\sum^{s}_{x}{d}", "\\sum"],["\\prod^{s}_{x}{d}", "\\prod"],
["\\coprod^{s}_{x}{d}", "\\coprod"],["\\int^{s}_{x}{d}", "\\int"],["\\binom{n}{k}", "\\binom"]]'>
</label>

<label>
Expand Down
13 changes: 12 additions & 1 deletion mathquill4quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ window.mathquill4quill = function(dependencies) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

function isOperatorCommand(operator) {
if (/\[|\{|\(/.test(operator)) {
return false;
}
return true;
}

function enableMathQuillFormulaAuthoring(quill, options) {
options = options || {};

Expand Down Expand Up @@ -223,7 +230,11 @@ window.mathquill4quill = function(dependencies) {
throwOnError: false
});
button.onclick = () => {
mqField.cmd(operator);
if (isOperatorCommand(operator)) {
mqField.cmd(operator);
} else {
mqField.write(operator);
}
mqField.focus();
};

Expand Down
1 change: 1 addition & 0 deletions reactjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./index.css";
const CUSTOM_OPERATORS = [
["\\pm", "\\pm"],
["\\sqrt{x}", "\\sqrt"],
["\\sqrt[3]{x}", "\\sqrt[3]{}"],
["\\sqrt[n]{x}", "\\nthroot"],
["\\frac{x}{y}", "\\frac"],
["\\sum^{s}_{x}{d}", "\\sum"],
Expand Down

0 comments on commit 16df556

Please sign in to comment.