diff --git a/lib/pangea/choreographer/controllers/choreographer.dart b/lib/pangea/choreographer/controllers/choreographer.dart index 6c2e3c737..1525b25a0 100644 --- a/lib/pangea/choreographer/controllers/choreographer.dart +++ b/lib/pangea/choreographer/controllers/choreographer.dart @@ -414,7 +414,6 @@ class Choreographer { ); igc.igcTextData?.matches.clear(); } finally { - giveInputFocus(); setState(); } } @@ -464,7 +463,6 @@ class Choreographer { igc.igcTextData?.matches.clear(); } finally { setState(); - giveInputFocus(); } } diff --git a/lib/pangea/widgets/igc/span_card.dart b/lib/pangea/widgets/igc/span_card.dart index 65789442a..10c5a4382 100644 --- a/lib/pangea/widgets/igc/span_card.dart +++ b/lib/pangea/widgets/igc/span_card.dart @@ -81,6 +81,19 @@ class SpanCardState extends State { if (widget.scm.pangeaMatch?.match.choices == null) { return; } + + // if user ever selected the correct choice, automatically select it + final selectedCorrectIndex = + widget.scm.pangeaMatch!.match.choices!.indexWhere((choice) { + return choice.selected && choice.isBestCorrection; + }); + + if (selectedCorrectIndex != -1) { + selectedChoiceIndex = selectedCorrectIndex; + currentExpression = BotExpression.gold; + return; + } + if (selectedChoiceIndex == null) { DateTime? mostRecent; final numChoices = widget.scm.pangeaMatch!.match.choices!.length; @@ -173,28 +186,36 @@ class SpanCardState extends State { ); } - void onReplaceSelected() { + Future onReplaceSelected() async { addIgnoredTokenUses(); - widget.scm - .onReplacementSelect( - matchIndex: widget.scm.matchIndex, - choiceIndex: selectedChoiceIndex!, - ) - .then((value) => setState(() {})); + await widget.scm.onReplacementSelect( + matchIndex: widget.scm.matchIndex, + choiceIndex: selectedChoiceIndex!, + ); + _showFirstMatch(); } void onIgnoreMatch() { - MatrixState.pAnyState.closeOverlay(); addIgnoredTokenUses(); Future.delayed( Duration.zero, () { widget.scm.onIgnore(); + _showFirstMatch(); }, ); } + void _showFirstMatch() { + if (widget.scm.choreographer.igc.igcTextData != null && + widget.scm.choreographer.igc.igcTextData!.matches.isNotEmpty) { + widget.scm.choreographer.igc.showFirstMatch(context); + } else { + MatrixState.pAnyState.closeOverlay(); + } + } + @override Widget build(BuildContext context) { return WordMatchContent(controller: this);