diff --git a/src/mathquill.d.ts b/src/mathquill.d.ts
index 34751c201..0db653079 100644
--- a/src/mathquill.d.ts
+++ b/src/mathquill.d.ts
@@ -42,10 +42,10 @@ declare namespace MathQuill {
setAriaLabel(str: string): this;
blur(): this;
focus(): this;
+ select(): this;
}
interface EditableMathQuill extends BaseMathQuill {
- select: () => EditableMathQuill;
moveToRightEnd: () => EditableMathQuill;
moveToLeftEnd: () => EditableMathQuill;
cmd: (latex: string) => EditableMathQuill;
diff --git a/src/publicapi.ts b/src/publicapi.ts
index c05ba8c01..787e1aa4e 100644
--- a/src/publicapi.ts
+++ b/src/publicapi.ts
@@ -359,6 +359,10 @@ function getInterface(v: number): MathQuill.v3.API | MathQuill.v1.API {
if (this.__controller.editable) this.__controller.scrollHoriz();
return this;
}
+ select() {
+ this.__controller.selectAll();
+ return this;
+ }
blur() {
this.__controller.getTextarea().blur();
return this;
@@ -376,10 +380,6 @@ function getInterface(v: number): MathQuill.v3.API | MathQuill.v1.API {
this.__controller.editablesTextareaEvents();
return this;
}
- select() {
- this.__controller.selectAll();
- return this;
- }
clearSelection() {
this.__controller.cursor.clearSelection();
return this;
diff --git a/src/services/mouse.ts b/src/services/mouse.ts
index 12c790ad7..ae8e03b48 100644
--- a/src/services/mouse.ts
+++ b/src/services/mouse.ts
@@ -115,7 +115,8 @@ class Controller_mouse extends Controller_latex {
};
if (ctrlr.blurred) {
- textarea.focus();
+ //for static mathquills, we focus on mousemove
+ if (this.editable) textarea.focus();
// focus call may bubble to clients, who may then write to
// mathquill, triggering cancelSelectionOnEdit. If that happens, we
// don't want to stop the cursor blink or bind listeners,
diff --git a/test/unit/focusBlur.test.js b/test/unit/focusBlur.test.js
index 66b60ef7e..a82d5c042 100644
--- a/test/unit/focusBlur.test.js
+++ b/test/unit/focusBlur.test.js
@@ -143,4 +143,38 @@ suite('focusBlur', function () {
mq.blur();
assertHasFocus(mq, 'math field', 'not');
});
+
+ test('static math does not focus on click', function (done) {
+ var mq = MQ.StaticMath(
+ $('1234\\times 10^{23}').appendTo('#mock')[0]
+ );
+
+ const clickEvent = new Event('mousedown', {
+ bubbles: true,
+ cancelable: true
+ });
+
+ mq.el().dispatchEvent(clickEvent);
+ setTimeout(function () {
+ assertHasFocus(mq, 'math field', 'not');
+ done();
+ }, 100);
+ });
+
+ test('editable math does focus on click', function (done) {
+ var mq = MQ.MathField(
+ $('1234\\times 10^{23}').appendTo('#mock')[0]
+ );
+
+ const clickEvent = new Event('mousedown', {
+ bubbles: true,
+ cancelable: true
+ });
+
+ mq.el().dispatchEvent(clickEvent);
+ setTimeout(function () {
+ assertHasFocus(mq, 'math field');
+ done();
+ }, 100);
+ });
});