Fix cursor position for single-digit integer in currency mask (x.xx case)#2875
Draft
Fix cursor position for single-digit integer in currency mask (x.xx case)#2875
Conversation
Copilot
AI
changed the title
[WIP] Fix cursor position issue on currency mask input
Fix cursor position for single-digit integer in currency mask (x.xx case)
Mar 31, 2026
RobinHerbots
requested changes
Apr 7, 2026
Owner
RobinHerbots
left a comment
There was a problem hiding this comment.
@copilot ,
No code changes?
…ase) Agent-Logs-Url: https://github.com/RobinHerbots/Inputmask/sessions/20760598-8283-4b3e-acf4-5ac078f8d507 Co-authored-by: RobinHerbots <318447+RobinHerbots@users.noreply.github.com>
Contributor
Author
Fixed in 0b9ce8f. The change is in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 currency input has a single integer digit (e.g.
"1.50"), clicking anywhere in the field positions the cursor incorrectly (jumps to end), while"0.xx"(radixFocus snap) and"xx.xx"(two+ digits, lvp) both behave correctly.Root Cause
In
lib/positioning.js,doRadixFocusiteratesvalidPositionsusingvps.lengthas the loop bound:After
stripLeadingZeroessplices entries from the sparsevalidPositionsarray,vps.lengthcan be smaller than the actual highest-indexed integer digit position. The loop never reaches the integer digit,doRadixFocusincorrectly returnstrue, andseekNext(radixPos)withnumericInputresolves to position0— whichtranslatePositionmaps to the display end.Fix
Switch the loop from index-based (
vps.lengthbound) tofor...inover the sparse array, so all defined positions are checked regardless of array length anomalies from splicing:This ensures
doRadixFocuscorrectly returnsfalsewhen a non-placeholder integer digit exists, falling through to thelvppath that places the caret at the clicked position.