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

Support overrideKeystroke on static math #304

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

jared-hughes
Copy link

No description provided.

@jared-hughes jared-hughes requested review from eluberoff and mikehaverstock and removed request for eluberoff September 19, 2024 00:40
if (controller.KIND_OF_MQ === 'StaticMath') {
controller.addTextareaEventListeners({
keydown: (evt) => {
controller.options.overrideKeystroke?.(getMQKeyName(evt!), evt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a little weird to be using something named overrideKeystroke when this does not actually override the keystroke handling function. This is purely adding a listener, right? When we use overrideKeystroke elsewhere we do actually avoid calling the default handler.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, but this is on the StaticMath, which doesn't have an existing keystroke handling function. ('Copy' is not a keydown; it's a copy event). So it is overriding nothing with overrideKeystroke. I've added a comment to this effect.

textarea.value = text;
if (text) textarea.select();
};
const textarea = this.getTextareaOrThrow();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we guaranteed that the textarea exists at this point and that it won't change? Do we not delay instantiation of that textarea ever? I'm wondering why we might sometimes throw when fetching the textarea and if it's a good idea to throw in the middle of setting up a mathquill.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we're guaranteed that the textarea exists and it doesn't change. Since #303, we are no longer adding and removing a textarea in static math. I've added some comments noting the order of initialization in commands/math.ts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the "OrThrow" from the name then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've done that. Kept the throw in place though (converted it to a pray). Better an early error there instead of a ! assertion.

@jared-hughes jared-hughes force-pushed the jared/static-saneKeyboardEvents branch from 1faf843 to 6a07b06 Compare September 20, 2024 20:54
Convert throw to pray.
@jared-hughes jared-hughes merged commit 1eb8dd0 into main Sep 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants