add helpful function to get recent normalization matches

This commit is contained in:
ggurdin 2025-11-05 14:57:00 -05:00
parent 69ae340060
commit 5829c3e1ca
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
7 changed files with 25 additions and 26 deletions

View file

@ -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<ChatPageWithRoom>
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<ChatPageWithRoom>
WidgetsBinding.instance.addPostFrameCallback((_) async {
await choreographer.requestLanguageAssistance();
onSelectMatch(choreographer.firstOpenMatch);
onSelectMatch(choreographer.igcController.firstOpenMatch);
});
},
),

View file

@ -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<PangeaMatchState>? get openIGCMatches => igcController.openMatches;
List<PangeaMatchState>? 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;

View file

@ -29,7 +29,8 @@ class IgcController {
PangeaMatchState? get openMatch => _igcTextData?.openMatch;
PangeaMatchState? get firstOpenMatch => _igcTextData?.firstOpenMatch;
List<PangeaMatchState>? get openMatches => _igcTextData?.openMatches;
List<PangeaMatchState>? get closedMatches => _igcTextData?.closedMatches;
List<PangeaMatchState>? get recentNormalizationMatches =>
_igcTextData?.recentNormalizationMatches;
List<PangeaMatchState>? get openNormalizationMatches =>
_igcTextData?.openNormalizationMatches;

View file

@ -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<InlineSpan> _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 = <InlineSpan>[];
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,

View file

@ -34,7 +34,8 @@ class IGCTextData {
List<PangeaMatchState> get openMatches => _state.openMatches;
List<PangeaMatchState> get closedMatches => _state.closedMatches;
List<PangeaMatchState> get recentNormalizationMatches =>
_state.recentNormalizationMatches;
PangeaMatchState? get firstOpenMatch => _state.firstOpenMatch;

View file

@ -51,6 +51,13 @@ class IGCTextState {
List<PangeaMatchState> get closedMatches => _closedMatches;
List<PangeaMatchState> get recentNormalizationMatches =>
closedMatches.reversed
.takeWhile(
(m) => m.updatedMatch.status == PangeaMatchStatus.automatic,
)
.toList();
List<PangeaMatchState> get openNormalizationMatches => _openMatches
.where((match) => match.updatedMatch.match.isNormalizationError())
.toList();

View file

@ -75,7 +75,8 @@ class StartIGCButtonState extends State<StartIGCButton>
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);
}
}