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

keystroke and typedText should return boolean #53

Closed
NSoiffer opened this issue Feb 19, 2018 · 3 comments
Closed

keystroke and typedText should return boolean #53

NSoiffer opened this issue Feb 19, 2018 · 3 comments

Comments

@NSoiffer
Copy link
Collaborator

NSoiffer commented Feb 19, 2018

Description

mathlive has two public functions for handling keys:

  • MathField.prototype.keystroke
  • MathField.prototype.typedText

The functions sometimes handle the key input, and sometimes they pass on handling it. There is currently no way to tell if they did something or not. If they returned a boolean indicating whether they handled character, than it would be possible to call one, and if it didn't handle the key call the other or otherwise process the input.

Implementation Notes:

Making this work for keystroke appears trivial because the function it calls returns a boolean.

For typedText, I'm not sure if this is easy or not. render is always called at the end, so perhaps everything is handled, but I suspect not. Maybe a hook into the selection changing could be used.

@NSoiffer
Copy link
Collaborator Author

Also...
MathField.prototype.keystroke should take as a second arg the event. If not, then _onKeystroke has null for its second param and eventually the code evt.preventDefault(); (etc) could get called, which will generate an error.

@arnog
Copy link
Owner

arnog commented Feb 24, 2018

I've added a boolean as a return value for keystroke(). Not sure why it wasn't there in the first place.
Also added an optional evt argument. Note that this function was intended to be used in cases where a synthetic event was generated, and therefore no 'real' event object may be available. However, as you pointed out, the internal implementation actually did not handle correctly the missing event. So, this is now fixed, but for good measure, you can also pass an optional event if you have one.

For typedText(), the definition of whether something has been 'handled' or not is more difficult, since really any string could be passed. For example, it would be valid to pass '{}' as a string. Or " ". So, what's the definition of "handled"? Is it whether the formula has been modified? Could you give me an example of some value you would want to pass on to typedText() where you would want it to consider having "not handled" the input?

@arnog arnog closed this as completed in 47886f5 Feb 24, 2018
@NSoiffer
Copy link
Collaborator Author

NSoiffer commented Feb 24, 2018 via email

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

No branches or pull requests

2 participants