diff --git a/lib/providers/tx_meta_provider.dart b/lib/providers/tx_meta_provider.dart index 48d59eb..195a88e 100644 --- a/lib/providers/tx_meta_provider.dart +++ b/lib/providers/tx_meta_provider.dart @@ -521,10 +521,15 @@ class TxMetaController extends ChangeNotifier { } /// Replace labels on every transaction in [txs] (per-id overrides). + /// + /// When [matchPattern] is set (apply-to-matched), also refreshes the + /// merchant rule so future transactions matching the pattern inherit the + /// full label set (parent + sub-labels). Future setLabelsForMany( List txs, - List labelIds, - ) async { + List labelIds, { + String? matchPattern, + }) async { if (txs.isEmpty) return; final expanded = expandWithAncestors([ @@ -545,6 +550,22 @@ class TxMetaController extends ChangeNotifier { : current.copyWith(labelIds: unique); } _byId = nextById; + + final pattern = (matchPattern ?? '').trim().toLowerCase(); + if (pattern.isNotEmpty) { + final nextRules = Map>.of(_labelsByMerchant); + if (unique.isEmpty) { + nextRules.remove(pattern); + for (final tx in txs) { + nextRules.remove(tx.merchantKey); + nextRules.remove(tx.descriptionKey); + } + } else { + nextRules[pattern] = unique; + } + _labelsByMerchant = nextRules; + } + _schedulePersist(); } diff --git a/lib/screens/transaction_detail_screen.dart b/lib/screens/transaction_detail_screen.dart index 8f606f3..c8e35d5 100644 --- a/lib/screens/transaction_detail_screen.dart +++ b/lib/screens/transaction_detail_screen.dart @@ -188,6 +188,7 @@ class _TransactionDetailScreenState extends State { await meta.setLabelsForMany( targets, _draftLabelIds.toList(growable: false), + matchPattern: toMatched ? _pattern : null, ); if (!mounted) return; setState(() {