From beeaaf30354cddd1e192cb4f8d79fc9ad9a2de9a Mon Sep 17 00:00:00 2001 From: Chris Wenn Date: Sat, 24 Oct 2026 01:47:21 +0400 Subject: [PATCH] fix: keep date/size condition unit when editing the number field 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 #45 --- CHANGELOG.md | 1 + Sources/ForelApp/Views/RuleEditorView.swift | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index caf84ed..118b5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to Forel are documented here. Format loosely follows ### Fixed - Date Added conditions no longer crash when reading a file's timestamp. +- Editing the number in a relative date or size condition no longer resets its unit, which could silently turn "2 Months" into "2 Days". ## [1.1.0] - 2026-10-22 diff --git a/Sources/ForelApp/Views/RuleEditorView.swift b/Sources/ForelApp/Views/RuleEditorView.swift index 0ed76fd..ba507d5 100644 --- a/Sources/ForelApp/Views/RuleEditorView.swift +++ b/Sources/ForelApp/Views/RuleEditorView.swift @@ -679,7 +679,9 @@ private struct RelativeDateValueEditor: View { } private var parts: (number: String, unit: String) { - let pieces = value.split(separator: " ", maxSplits: 1).map(String.init) + // omittingEmptySubsequences: false keeps "" as the number when the + // field is transiently empty mid-edit, so the unit survives keystrokes. + let pieces = value.split(separator: " ", maxSplits: 1, omittingEmptySubsequences: false).map(String.init) let number = pieces.first?.filter(\.isNumber) let unit = pieces.count > 1 ? pieces[1] : "days" return ((number?.isEmpty == false ? number! : "7"), units.contains(unit) ? unit : "days") @@ -714,7 +716,7 @@ private struct SizeValueEditor: View { } private var parts: (number: String, unit: String) { - let pieces = value.split(separator: " ", maxSplits: 1).map(String.init) + let pieces = value.split(separator: " ", maxSplits: 1, omittingEmptySubsequences: false).map(String.init) let number = pieces.first?.filter { $0.isNumber || $0 == "." } let rawUnit = pieces.count > 1 ? pieces[1] : "MB" let unit = ["bytes", "KB", "MB", "GB"].contains(rawUnit) ? rawUnit : "MB"