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

Caret jumps over the last digit and decimal character when pressing arrow key once #767

Open
strobh opened this issue Apr 27, 2023 · 2 comments

Comments

@strobh
Copy link

strobh commented Apr 27, 2023

Current behavior

Consider the following situation: An autoNumeric input field contains the number 50,000.23 and the user wants to replace it with 50,001.23. The caret/text cursor is positioned in the front of the number (|50,000.23).
The user presses the right arrow key until the caret is positioned on the right of the last integer digit (50,000|.23), presses backspace and replaces the zero with a one. But surprise: When pressing the right arrow key on 50,00|0.23, the caret moves two characters to the right of the decimal character instead (50,000.|23) and if the user presses backspace the decimal character is removed instead of the last integer digit (leading to a result of 500,001.|23 if the user inserts the decimal character again).

The behavior can be seen in this screen recording:
https://user-images.githubusercontent.com/1754883/234876454-38bfa195-337e-4aae-9790-19a39c7fcd71.mp4

Expected behavior

The caret should move from 50,00|0.23 to 50,000|.23 when pressing the right arrow key.

Steps to reproduce the problem (see video)

  1. autoNumeric version: v.4.8.1
  2. Browser: Chrome v112.0.5615.137
  3. OS: macOS
  4. Default options of autoNumeric

Link to live example

The described behavior can be checked out in the autoNumeric configurator: http://autonumeric.org/configurator

Thank you for developing this amazing package!

@AlexandreBonneau
Copy link
Member

Hello and thanks for taking the time to report your feature request.
This is indeed the intended behavior ; whenever the arrow left or right is used, the caret must always be placed against the next number, ignoring any group separators or decimal point.

This is a behavior that predates me becoming the maintainer of AutoNumeric, so I'm guessing this is the way it was since 2009!

Now the question is; should the caret stops before and after the decimal point? Or should you be able for instance as it is now the case to count the number of numbers using the arrow keys?

To be honest I'm not sure, as I got used to the way to just do an additional ArrowRight after having passed the decimal point. Also, since this is the first time in 14 years somebody created an issue about this, I'm not sure this is really needed by the masses.

I guess we could add yet another option to make that behavior configurable, but trying to keep the code as small as possible, this goes against this idea, specially if this not needed by many people.

If somebody else want this feature, please post here and I'll see what I can do.
If this has not gathered any attention in the span of the next months, then perhaps we'll close this as a 'too-niche-usecase'.
Would that be alright with you?

@strobh
Copy link
Author

strobh commented Jun 27, 2023

Hello and sorry it took so long for my reply.

Thank you for the detailed answer and for explaining the background and that this is the intended behaviour! The approach you suggested sounds perfectly reasonable to me.

As I said, for me it would be more intuitive if the cursor stopped at the decimal separator and didn't jump over it, but if I'm the only one who's bothered by that, you can close this issue sooner or later. If anyone else expresses interest in this, I'd be happy to create a PR. I have already looked into the code and would have thought of an option jumpOverDecimalCharacter (with the possible values true/jump and false/doNotJump) or something similar. But before other opinions come in, I'm not putting any work into it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants