From 487e2255a5aceb19ee869df41cf892cdcf87a3f9 Mon Sep 17 00:00:00 2001 From: Eli Luberoff Date: Sun, 24 Nov 2024 21:43:19 -0600 Subject: [PATCH 1/3] don't focus textarea on tapstart for static math we only need focus when something is selected, and the fact that we were focusing prematurely resulted in some small behavior inconsistencies between the first and second time e.g. that you'd click on a static table cell in the calculator --- src/services/mouse.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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, From 4979d5a181972aaca13c375fe3bf107f139da3c1 Mon Sep 17 00:00:00 2001 From: Eli Luberoff Date: Fri, 6 Dec 2024 19:03:23 -0500 Subject: [PATCH 2/3] move "select" method to base so that we can use it in StaticMath as well --- src/mathquill.d.ts | 2 +- src/publicapi.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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; From 70dae6a8d1eec8777f7a607b0678dfbd7073699c Mon Sep 17 00:00:00 2001 From: Eli Luberoff Date: Fri, 6 Dec 2024 19:03:23 -0500 Subject: [PATCH 3/3] add tests that mousedown in static math doesn't focus --- test/unit/focusBlur.test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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); + }); });