feat: initial work to prevent giving points for copy-pasted text (#2345)
* feat: initial work to prevent giving points for copy-pasted text * chore: replace tokenization with comparing token content with pasted content
This commit is contained in:
parent
e7a2d12a3c
commit
3acab885d9
4 changed files with 30 additions and 11 deletions
|
|
@ -66,11 +66,7 @@ class Choreographer {
|
|||
_initialize() {
|
||||
tts = TtsController(chatController: chatController);
|
||||
_textController = PangeaTextController(choreographer: this);
|
||||
InputPasteListener(
|
||||
_textController,
|
||||
// TODO, do something on paste
|
||||
() => debugPrint("on paste"),
|
||||
);
|
||||
InputPasteListener(_textController, onPaste);
|
||||
itController = ITController(this);
|
||||
igc = IgcController(this);
|
||||
errorService = ErrorService(this);
|
||||
|
|
@ -571,6 +567,10 @@ class Choreographer {
|
|||
giveInputFocus();
|
||||
}
|
||||
|
||||
Future<void> onPaste(value) async {
|
||||
choreoRecord.pastedStrings.add(value);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
_textController.dispose();
|
||||
_trialStream?.cancel();
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ class ChoreoRecord {
|
|||
/// there is not a 1-to-1 map from steps to matches
|
||||
List<ChoreoRecordStep> choreoSteps;
|
||||
|
||||
// String current;
|
||||
|
||||
List<PangeaMatch> openMatches;
|
||||
|
||||
final Set<String> pastedStrings = {};
|
||||
|
||||
ChoreoRecord({
|
||||
required this.choreoSteps,
|
||||
required this.openMatches,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import 'package:fluffychat/pangea/choreographer/widgets/igc/pangea_text_controll
|
|||
|
||||
class InputPasteListener {
|
||||
final PangeaTextController controller;
|
||||
final VoidCallback onPaste;
|
||||
final Function(String) onPaste;
|
||||
|
||||
String _currentText = '';
|
||||
|
||||
|
|
@ -14,10 +14,18 @@ class InputPasteListener {
|
|||
this.onPaste,
|
||||
) {
|
||||
controller.addListener(() {
|
||||
if (controller.editType != EditType.keyboard) return;
|
||||
final difference =
|
||||
controller.text.characters.length - _currentText.characters.length;
|
||||
if (difference > 1) onPaste();
|
||||
if (difference > 1 && controller.editType == EditType.keyboard) {
|
||||
onPaste(
|
||||
controller.text.characters
|
||||
.getRange(
|
||||
_currentText.characters.length,
|
||||
controller.text.characters.length,
|
||||
)
|
||||
.join(),
|
||||
);
|
||||
}
|
||||
_currentText = controller.text;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,8 +119,19 @@ class PangeaRepresentation {
|
|||
);
|
||||
|
||||
// for each token, record whether selected in ga, ta, or wa
|
||||
final tokensToSave =
|
||||
List<PangeaToken> tokensToSave =
|
||||
tokens.where((token) => token.lemma.saveVocab).toList();
|
||||
if (choreo != null && choreo.pastedStrings.isNotEmpty) {
|
||||
tokensToSave = tokensToSave
|
||||
.where(
|
||||
(token) => !choreo.pastedStrings.any(
|
||||
(pasted) => pasted
|
||||
.toLowerCase()
|
||||
.contains(token.text.content.toLowerCase()),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
for (final token in tokensToSave) {
|
||||
uses.addAll(
|
||||
_getUsesForToken(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue