From 5829c3e1ca23ac52ae97ede89bdb8e563566b2c1 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 5 Nov 2025 14:57:00 -0500 Subject: [PATCH] add helpful function to get recent normalization matches --- lib/pages/chat/chat.dart | 5 ++--- .../choreographer_state_extension.dart | 9 -------- .../controllers/igc_controller.dart | 3 ++- .../controllers/pangea_text_controller.dart | 21 +++++++++---------- .../models/igc_text_data_model.dart | 3 ++- .../choreographer/models/igc_text_state.dart | 7 +++++++ .../widgets/start_igc_button.dart | 3 ++- 7 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index af791f5bc..5c2f7c37a 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -41,7 +41,6 @@ import 'package:fluffychat/pangea/chat/utils/unlocked_morphs_snackbar.dart'; import 'package:fluffychat/pangea/chat/widgets/event_too_large_dialog.dart'; import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; import 'package:fluffychat/pangea/choreographer/controllers/extensions/choregrapher_user_settings_extension.dart'; -import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart'; import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_ui_extension.dart'; import 'package:fluffychat/pangea/choreographer/controllers/pangea_text_controller.dart'; import 'package:fluffychat/pangea/choreographer/enums/edit_type.dart'; @@ -1765,7 +1764,7 @@ class ChatController extends State PaywallCard.show(context, choreographer.inputTransformTargetKey); return; } on OpenMatchesException { - onSelectMatch(choreographer.firstOpenMatch); + onSelectMatch(choreographer.igcController.firstOpenMatch); return; } // Pangea# @@ -2235,7 +2234,7 @@ class ChatController extends State WidgetsBinding.instance.addPostFrameCallback((_) async { await choreographer.requestLanguageAssistance(); - onSelectMatch(choreographer.firstOpenMatch); + onSelectMatch(choreographer.igcController.firstOpenMatch); }); }, ), diff --git a/lib/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart b/lib/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart index fb6443fa1..fa8258ab6 100644 --- a/lib/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart +++ b/lib/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart @@ -2,7 +2,6 @@ import 'package:fluffychat/pangea/choreographer/controllers/choreographer.dart'; import 'package:fluffychat/pangea/choreographer/controllers/extensions/choregrapher_user_settings_extension.dart'; import 'package:fluffychat/pangea/choreographer/enums/assistance_state_enum.dart'; import 'package:fluffychat/pangea/choreographer/enums/choreo_mode.dart'; -import 'package:fluffychat/pangea/choreographer/models/pangea_match_state.dart'; extension ChoregrapherUserSettingsExtension on Choreographer { bool get isRunningIT { @@ -10,14 +9,6 @@ extension ChoregrapherUserSettingsExtension on Choreographer { itController.currentITStep.value?.isFinal != true; } - String? get currentIGCText => igcController.currentText; - PangeaMatchState? get openMatch => igcController.openMatch; - PangeaMatchState? get firstOpenMatch => igcController.firstOpenMatch; - List? get openIGCMatches => igcController.openMatches; - List? get closedIGCMatches => igcController.closedMatches; - bool get canShowFirstIGCMatch => igcController.canShowFirstMatch; - bool get hasIGCTextData => igcController.hasIGCTextData; - AssistanceState get assistanceState { final isSubscribed = pangeaController.subscriptionController.isSubscribed; if (isSubscribed == false) return AssistanceState.noSub; diff --git a/lib/pangea/choreographer/controllers/igc_controller.dart b/lib/pangea/choreographer/controllers/igc_controller.dart index d325890aa..eb9b4af38 100644 --- a/lib/pangea/choreographer/controllers/igc_controller.dart +++ b/lib/pangea/choreographer/controllers/igc_controller.dart @@ -29,7 +29,8 @@ class IgcController { PangeaMatchState? get openMatch => _igcTextData?.openMatch; PangeaMatchState? get firstOpenMatch => _igcTextData?.firstOpenMatch; List? get openMatches => _igcTextData?.openMatches; - List? get closedMatches => _igcTextData?.closedMatches; + List? get recentNormalizationMatches => + _igcTextData?.recentNormalizationMatches; List? get openNormalizationMatches => _igcTextData?.openNormalizationMatches; diff --git a/lib/pangea/choreographer/controllers/pangea_text_controller.dart b/lib/pangea/choreographer/controllers/pangea_text_controller.dart index 8acf059b0..7f3fb5eb0 100644 --- a/lib/pangea/choreographer/controllers/pangea_text_controller.dart +++ b/lib/pangea/choreographer/controllers/pangea_text_controller.dart @@ -4,7 +4,6 @@ import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:fluffychat/pangea/choreographer/constants/choreo_constants.dart'; import 'package:fluffychat/pangea/choreographer/constants/match_rule_ids.dart'; -import 'package:fluffychat/pangea/choreographer/controllers/extensions/choreographer_state_extension.dart'; import 'package:fluffychat/pangea/choreographer/enums/pangea_match_status.dart'; import 'package:fluffychat/pangea/choreographer/models/pangea_match_model.dart'; import 'package:fluffychat/pangea/choreographer/models/pangea_match_state.dart'; @@ -112,11 +111,11 @@ class PangeaTextController extends TextEditingController { return _buildPaywallSpan(style); } - if (!choreographer.hasIGCTextData) { + if (!choreographer.igcController.hasIGCTextData) { return TextSpan(text: text, style: style); } - final parts = text.split(choreographer.currentIGCText!); + final parts = text.split(choreographer.igcController.currentText!); if (parts.length != 2) { return TextSpan(text: text, style: style); } @@ -141,7 +140,7 @@ class PangeaTextController extends TextEditingController { PangeaMatchState match, TextStyle style, ) { - final span = choreographer.currentIGCText!.characters + final span = choreographer.igcController.currentText!.characters .getRange( match.updatedMatch.match.offset, match.updatedMatch.match.offset + match.updatedMatch.match.length, @@ -177,20 +176,19 @@ class PangeaTextController extends TextEditingController { List _buildTokenSpan({ TextStyle? defaultStyle, }) { - final openMatches = choreographer.openIGCMatches ?? const []; - final closedMatches = choreographer.closedIGCMatches ?? const []; + final openMatches = choreographer.igcController.openMatches ?? const []; + final normalizationMatches = + choreographer.igcController.recentNormalizationMatches ?? const []; final textSpanMatches = [ ...openMatches, - ...closedMatches.reversed.takeWhile( - (m) => m.updatedMatch.status == PangeaMatchStatus.automatic, - ), + ...normalizationMatches, ]..sort( (a, b) => a.updatedMatch.match.offset.compareTo(b.updatedMatch.match.offset), ); - final currentText = choreographer.currentIGCText!; + final currentText = choreographer.igcController.currentText!; final spans = []; int cursor = 0; @@ -202,7 +200,8 @@ class PangeaTextController extends TextEditingController { spans.add(TextSpan(text: text, style: defaultStyle)); } - final openMatch = choreographer.openMatch?.updatedMatch.match; + final openMatch = + choreographer.igcController.openMatch?.updatedMatch.match; final style = _textStyle( match.updatedMatch, defaultStyle, diff --git a/lib/pangea/choreographer/models/igc_text_data_model.dart b/lib/pangea/choreographer/models/igc_text_data_model.dart index acca08551..06e2294c7 100644 --- a/lib/pangea/choreographer/models/igc_text_data_model.dart +++ b/lib/pangea/choreographer/models/igc_text_data_model.dart @@ -34,7 +34,8 @@ class IGCTextData { List get openMatches => _state.openMatches; - List get closedMatches => _state.closedMatches; + List get recentNormalizationMatches => + _state.recentNormalizationMatches; PangeaMatchState? get firstOpenMatch => _state.firstOpenMatch; diff --git a/lib/pangea/choreographer/models/igc_text_state.dart b/lib/pangea/choreographer/models/igc_text_state.dart index a4caab60b..ffe278ce6 100644 --- a/lib/pangea/choreographer/models/igc_text_state.dart +++ b/lib/pangea/choreographer/models/igc_text_state.dart @@ -51,6 +51,13 @@ class IGCTextState { List get closedMatches => _closedMatches; + List get recentNormalizationMatches => + closedMatches.reversed + .takeWhile( + (m) => m.updatedMatch.status == PangeaMatchStatus.automatic, + ) + .toList(); + List get openNormalizationMatches => _openMatches .where((match) => match.updatedMatch.match.isNormalizationError()) .toList(); diff --git a/lib/pangea/choreographer/widgets/start_igc_button.dart b/lib/pangea/choreographer/widgets/start_igc_button.dart index 136979212..f39fa4c5e 100644 --- a/lib/pangea/choreographer/widgets/start_igc_button.dart +++ b/lib/pangea/choreographer/widgets/start_igc_button.dart @@ -75,7 +75,8 @@ class StartIGCButtonState extends State widget.controller.showLanguageMismatchPopup(); } else { await widget.controller.choreographer.requestLanguageAssistance(); - final openMatch = widget.controller.choreographer.firstOpenMatch; + final openMatch = + widget.controller.choreographer.igcController.firstOpenMatch; widget.controller.onSelectMatch(openMatch); } }