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

Arrays, Enter and Intuition #225

Closed
saivan opened this issue Jul 3, 2019 · 6 comments
Closed

Arrays, Enter and Intuition #225

saivan opened this issue Jul 3, 2019 · 6 comments
Assignees
Labels
bug feature Request for a new feature or functionality, as opposed to a defect in an existing feature. medium priority

Comments

@saivan
Copy link

saivan commented Jul 3, 2019

Describe the bug
I can't call it a bug, but I did test it on a few people, and I believe the current behaviour is too complicated and unintuitive for most users. Basically, when a user hits enter, they are marking the "end" of an input.

Perhaps instead of using the key to make new rows in an array, we should just go with the latex shortcuts that most people editing matrices will be familiar with (&) and (\\). Alternatively, the matlab shortcuts also seem like a good fit (, for new column and ; for new row).

I noticed a few confused faces on some of the examples below:

To Reproduce
In a mathlive document, type s i n ( 3 <enter>
This will create an array inside of sin

image

Expected behavior
Pressing enter at that location should have removed focus from the editor.
I propose that:

Enter should always commit the current document whether or not the input is valid

Environment
Any (but I'm on a mac)

@arnog
Copy link
Owner

arnog commented Jul 3, 2019

Hmmm... I can see that the current behavior could be unexpected. I'm not sure what's the best way to improve it, though.

First, the example you provide with "sin()" is interesting. This is triggered because when inside a parenthesized expression, return/tab are treated as commands to add rows/columns. But that doesn't really make sense here, since it's a scalar argument. So, that should probably be special cased.

Second, I'm not sure what you mean by "commit". Do you mean losing the focus? But then having no focus? That doesn't seem to be very useful.

Also, you may already know this, but it is currently possible to intercept and handle return in any way you'd like, by specifying a onKeystroke handler in the config. You can then prevent the default behavior of adding a row to be performed,

That same handler can be used to redefine the keyboard shortcuts to add a column and row.

I'll give it some more thoughts...

@arnog arnog added bug feature Request for a new feature or functionality, as opposed to a defect in an existing feature. medium priority labels Jul 3, 2019
@saivan
Copy link
Author

saivan commented Jul 4, 2019

Sorry yes to be clear. Generally, I use mathlive to drive an external equation renderer, and when I press enter (or return), it means; I'm done typing :P I know that I can intercept the handler, but it would be nice to have reasonable default behaviour.

I can see the reason enter was used to mean new line, but should rows in a matrix/array really be treated as "new lines"

The control comma keyboard shortcut to add a new column to matrices / arrays was also really unintuitive and I had to go digging through the docs to work it out :P. It would generally be a good idea to use conventions that people are already familiar with (or to expose keyboard shortcuts as an object that can be remapped at run-time)

@saivan
Copy link
Author

saivan commented Jul 4, 2019

Also, you're right about losing focus. That's probably a step too far for default behaviour. In my use case it makes sense, but as default behaviour; you're right that probably shouldn't be the way it works.

So let me amend that

Pressing enter should always call this method - sorry if I have the wrong one, but I think that is reasonable behaviour

@arnog
Copy link
Owner

arnog commented Jul 4, 2019

@SAVIAN: fair enough about the shortcuts. I picked the ones used by Excel/Google Sheets. Maybe we need to find better ones...

@saivan
Copy link
Author

saivan commented Jul 6, 2019

I think the comma and semicolon are pretty common. That would be my suggestion :p

@arnog
Copy link
Owner

arnog commented Oct 11, 2020

Added onCommit listener to mf.options. This listener is invoked when the user presses Enter or Return key, or when the field loses focus and its value has changed since it acquired it.

In addition, a change event is triggered when using a MathfieldElement.

The event previously named change has been renamed to input.

This mimics the behavior of <input> and <textarea> elements.

Changed the keyboard shortcuts to add columns and rows:

Shortcut Command
ctrl/cmd + Return/Enter addRowAfter
ctrl/cmd + shift + Return/Enter addRowBefore
ctrl/cmd + ; addRowAfter
ctrl/cmd + shift + ; addRowBefore
ctrl/cmd + , addColumnAfter
ctrl/cmd + shift + , addColumnBefore

Note that Enter/Return no longer create a matrix/vector when inside a parenthesized expression. Use ctrl/cmd + Return/Enter instead.

Added a commit command to programmatically trigger the onCommit listener change event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feature Request for a new feature or functionality, as opposed to a defect in an existing feature. medium priority
Projects
None yet
Development

No branches or pull requests

2 participants