Fix the text button on the mqeditor toolbutton. #1176
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.