Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small tweak to focus behavior #317

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mathquill.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/publicapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/services/mouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
jared-hughes marked this conversation as resolved.
Show resolved Hide resolved
// 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,
Expand Down
34 changes: 34 additions & 0 deletions test/unit/focusBlur.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
$('<span>1234\\times 10^{23}</span>').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(
$('<span>1234\\times 10^{23}</span>').appendTo('#mock')[0]
);

const clickEvent = new Event('mousedown', {
bubbles: true,
cancelable: true
});

mq.el().dispatchEvent(clickEvent);
setTimeout(function () {
assertHasFocus(mq, 'math field');
done();
}, 100);
});
});
Loading