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"