number_input: Built-in stepping, input restriction, and normalization#2460
Merged
Conversation
- `InputState` gains `step`/`step_by`/`min`/`max` builder methods and `set_*` runtime counterparts - `NumberInput` now defaults to `MaskPattern::Number` (number-only input, full-width normalization, bare dot auto-completion). Opt out via `set_mask_pattern(MaskPattern::None)` - New `NumberStep` enum supports fixed and by-value dynamic step strategies - Fix undo/redo with mask: use whole-document history entry when mask changes text - Fix invalid text trap: pre-existing invalid values can be edited to fix
Allow the step value to differ by direction at a range boundary (e.g. a price tick size where a boundary belongs to a different tick going up vs down), and simplify the internal stepping branch now that `step` defaults to 1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The previous three-tier price-tick example was both wrong (mismatched boundary ticks, duplicated branches) and too heavy for an example. Replace it with a clear two-tier case where the boundary 1.0 uses the lower tick going down and the upper tick going up, kept consistent across the story, docs, and unit test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Enhances
NumberInputto work out of the box and match web<input type=number>behavior:↑/↓keys and+/-buttons now step the value internally bystep(default1) and emitInputEvent::Change. Addstep/step_by/min/max(plusset_*runtime setters) onInputState.min/maxclamp on stepping and on blur; stepping follows web semantics (a step that can't move in the pressed direction is a no-op).step_byreceives the current value andStepActionso the step can differ by direction (e.g. a price tick size at a range boundary).NumberInput-bound state now only accepts a valid number (optional leading sign, digits, single decimal point) by default; opt out viaset_mask_pattern(MaskPattern::None, ...).12。5) are normalized to ASCII (12.5) for CJK IME users; a bare leading dot (.5) is completed to0.5.Undo/redo now records a whole-document change when the mask reshapes the text, so masked values undo correctly.