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

Fix the text button on the mqeditor toolbutton. #1176

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Jan 10, 2025

When a text block is entered all of the buttons on the toolbar are disabled. So when a user clicks on the text button, focus moves from the MathQuill input to the text button, and then the text block is created. At this point the text block is entered and the buttons disabled. Then focus is sent back to the MathQuill input. However, for some reasone with the button disabled, Google Chrome decides not to set the relatedTarget to the MathQuill textarea in the focusout event on the toolbar. Then the mqeditor focusout handler doesn't know that focus is going back to the MathQuill textarea and removes the toolbar. Then things go haywire, and that triggers the removal of the text block that was just created as well. Other browsers (Firefox and apparently Safari) still set the relatedTarget correctly in this case.

This implements a bit of a hack and sets a preventRemove flag on the toolbar when the buttons are disabled, and when the focusout handler occurs it sees the flag and doesn't remove the toolbar.

Edit: This now implements a better and simpler fix. This simply focuses the MathQuill input before issuing the toolbar button command. That means that the blur of the button and focus of the input occurs before the text block is started in the input. As a result the buttons of the toolbar are not disabled until after that all happens, and Google Chrome still sends the relatedTarget.

This fixes issue #1175.

Also remove an erroneous console.log that was left in a previous commit.

I also noticed another bug with text blocks while working on this. When focus is lost from the MathQuill input entirely and the cursor is inside an empty text block, then the text block is not removed as it should be. Furthermore, if the text block is clicked on after that an exception is thrown. This ensures the text block is removed in this case so that when focus returns the exception is not thrown. That bug is fixed in openwebwork/mathquill#35, and the dependency updated here.

When a text block is entered all of the buttons on the toolbar are
disabled.  So when a user clicks on the text button, focus moves from
the MathQuill input to the text button, and then the text block is
created.  At this point the text block is entered and the buttons
disabled.  Then focus is sent back to the MathQuill input.  However, for
some reasone with the button disabled, Google Chrome decides not to set
the relatedTarget to the MathQuill textarea in the focusout event on the
toolbar. Then the mqeditor focusout handler doesn't know that focus is
going back to the MathQuill textarea and removes the toolbar.  Then
things go haywire, and that triggers the removal of the text block that
was just created as well. Other browsers (Firefox and apparently Safari)
still set the relatedTarget correctly in this case.

This implements a bit of a hack and sets a preventRemove flag on the
toolbar when the buttons are disabled, and when the focusout handler
occurs it sees the flag and doesn't remove the toolbar.

This fixes issue openwebwork#1175.

Also remove an erroneous console.log that was left in a previous commit.

I also noticed another bug with text blocks while working on this.  When
focus is lost from the MathQuill input entirely and the cursor is inside
an empty text block, then the text block is not removed as it should be.
Furthermore, if the text block is clicked on after that an exception is
thrown.  This ensures the text block is removed in this case so that
when focus returns the exception is not thrown. That bug is fixed in
openwebwork/mathquill#35, and the dependency
updated here.
@somiaj somiaj merged commit e35b78d into openwebwork:develop Jan 14, 2025
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.

3 participants