Skip to content

fix: keep date/size condition unit when editing the number field - #77

Merged
lguichard merged 1 commit into
lab421:mainfrom
prismatic7:fix/date-unit-resets-on-edit
Oct 24, 2026
Merged

lguichard merged 1 commit into
lab421:mainfrom
prismatic7:fix/date-unit-resets-on-edit

Conversation

@prismatic7

Copy link
Copy Markdown
Contributor

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. parts then parses with split(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: false in both RelativeDateValueEditor.parts and SizeValueEditor.parts, so the empty number stays as "" and the unit survives the transient state. No stored-format change: values remain "N unit" and ConditionEvaluator parsing is untouched.

Verification

  • swift build clean.
  • swift test: 329 tests in 28 suites, all passed.
  • Negative test (structure-preserving variant of the old parse, standalone Swift): old logic turns the transient " months" into unit days → next keystroke writes "2 days"; new logic preserves months → "2 months". Assert on both.
  • Left to CI: no Xcode signing/UI harness run locally.

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
@lguichard

Copy link
Copy Markdown
Collaborator

@prismatic7 Thanks !

@lguichard
lguichard merged commit bde24f6 into lab421:main Oct 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Number/unit dropdown resets to 'Days' when editing the number field

2 participants