Repository navigation
fix: keep date/size condition unit when editing the number field - #77
Merged
Merged
Conversation
Editing the number input transiently stores an empty number with a
leading space (" months"); split(separator:) then omitted the empty
piece, the unit fell back to its default, and the next keystroke wrote
"2 days" over "2 months". Parse with omittingEmptySubsequences: false
so the unit survives mid-edit empty states, in both the relative date
and size value editors.
Fixes lab421#45
Collaborator
|
@prismatic7 Thanks ! |
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.
Fixes #45.
Problem
Editing the number field of a relative date condition (e.g. "1 Months") reset the unit dropdown to Days. The condition silently changed meaning — "1 Months" became "2 Days" — which matters because these conditions feed Trash/Delete actions.
The size condition (
SizeValueEditor) had the same bug: editing the number could reset KB/MB to the default.Root cause
The value is stored as the string
"1 months". When the number field is transiently empty mid-edit (backspace, or a filtered-out keystroke), the binding writes" months"with a leading space.partsthen parses withsplit(separator: " ", maxSplits: 1), which omits empty subsequences by default, so" months"yields a single piece,pieces.count == 1, and the unit falls back to its default ("days"/"MB"). The next keystroke writes"2 days".Fix
Parse with
omittingEmptySubsequences: falsein bothRelativeDateValueEditor.partsandSizeValueEditor.parts, so the empty number stays as""and the unit survives the transient state. No stored-format change: values remain"N unit"andConditionEvaluatorparsing is untouched.Verification
swift buildclean.swift test: 329 tests in 28 suites, all passed." months"into unitdays→ next keystroke writes"2 days"; new logic preservesmonths→"2 months". Assert on both.