feat: after completing match in igc, automatically go to next match (#1396)

* feat: after completing match in igc, automatically go to next match

* fix: if user ever chose correct choice in span card, auto-select it again on open
pull/1593/head
ggurdin 10 months ago committed by GitHub
parent 6cb6b7ebac
commit 064e2c6dd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -414,7 +414,6 @@ class Choreographer {
); );
igc.igcTextData?.matches.clear(); igc.igcTextData?.matches.clear();
} finally { } finally {
giveInputFocus();
setState(); setState();
} }
} }
@ -464,7 +463,6 @@ class Choreographer {
igc.igcTextData?.matches.clear(); igc.igcTextData?.matches.clear();
} finally { } finally {
setState(); setState();
giveInputFocus();
} }
} }

@ -81,6 +81,19 @@ class SpanCardState extends State<SpanCard> {
if (widget.scm.pangeaMatch?.match.choices == null) { if (widget.scm.pangeaMatch?.match.choices == null) {
return; 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) { if (selectedChoiceIndex == null) {
DateTime? mostRecent; DateTime? mostRecent;
final numChoices = widget.scm.pangeaMatch!.match.choices!.length; final numChoices = widget.scm.pangeaMatch!.match.choices!.length;
@ -173,28 +186,36 @@ class SpanCardState extends State<SpanCard> {
); );
} }
void onReplaceSelected() { Future<void> onReplaceSelected() async {
addIgnoredTokenUses(); addIgnoredTokenUses();
widget.scm await widget.scm.onReplacementSelect(
.onReplacementSelect( matchIndex: widget.scm.matchIndex,
matchIndex: widget.scm.matchIndex, choiceIndex: selectedChoiceIndex!,
choiceIndex: selectedChoiceIndex!, );
) _showFirstMatch();
.then((value) => setState(() {}));
} }
void onIgnoreMatch() { void onIgnoreMatch() {
MatrixState.pAnyState.closeOverlay();
addIgnoredTokenUses(); addIgnoredTokenUses();
Future.delayed( Future.delayed(
Duration.zero, Duration.zero,
() { () {
widget.scm.onIgnore(); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WordMatchContent(controller: this); return WordMatchContent(controller: this);

Loading…
Cancel
Save