feat: added util in choreographer to response to pasting in the input… (#2021)
* feat: added util in choreographer to response to pasting in the input bar
This commit is contained in:
parent
50c5fac8dc
commit
c9dbbe73b8
6 changed files with 57 additions and 12 deletions
|
|
@ -32,6 +32,7 @@ import 'package:fluffychat/pangea/analytics_misc/level_up.dart';
|
|||
import 'package:fluffychat/pangea/analytics_misc/put_analytics_controller.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/enums/edit_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/choreo_record.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
|
|
@ -269,7 +270,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final prefs = await SharedPreferences.getInstance();
|
||||
final draft = prefs.getString('draft_$roomId');
|
||||
if (draft != null && draft.isNotEmpty) {
|
||||
sendController.text = draft;
|
||||
// #Pangea
|
||||
// sendController.text = draft;
|
||||
sendController.setSystemText(draft, EditType.other);
|
||||
// Pangea#
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -820,7 +824,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
);
|
||||
|
||||
setState(() {
|
||||
sendController.text = pendingText;
|
||||
// #Pangea
|
||||
// sendController.text = pendingText;
|
||||
sendController.setSystemText(pendingText, EditType.other);
|
||||
// Pangea#
|
||||
_inputTextIsEmpty = pendingText.isEmpty;
|
||||
replyEvent = null;
|
||||
editEvent = null;
|
||||
|
|
@ -1755,7 +1762,10 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
void cancelReplyEventAction() => setState(() {
|
||||
if (editEvent != null) {
|
||||
sendController.text = pendingText;
|
||||
// #Pangea
|
||||
// sendController.text = pendingText;
|
||||
sendController.setSystemText(pendingText, EditType.other);
|
||||
// Pangea#
|
||||
pendingText = '';
|
||||
}
|
||||
replyEvent = null;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import 'package:fluffychat/pangea/choreographer/enums/edit_type.dart';
|
|||
import 'package:fluffychat/pangea/choreographer/models/choreo_record.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/it_step.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/models/pangea_match_model.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/utils/input_paste_listener.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/pangea_text_controller.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/paywall_card.dart';
|
||||
import 'package:fluffychat/pangea/common/controllers/pangea_controller.dart';
|
||||
|
|
@ -62,6 +63,11 @@ class Choreographer {
|
|||
}
|
||||
_initialize() {
|
||||
_textController = PangeaTextController(choreographer: this);
|
||||
InputPasteListener(
|
||||
_textController,
|
||||
// TODO, do something on paste
|
||||
() {},
|
||||
);
|
||||
itController = ITController(this);
|
||||
igc = IgcController(this);
|
||||
errorService = ErrorService(this);
|
||||
|
|
|
|||
|
|
@ -72,8 +72,10 @@ class ITController {
|
|||
void closeIT() {
|
||||
// if the user hasn't gone through any IT steps, reset the text
|
||||
if (completedITSteps.isEmpty && sourceText != null) {
|
||||
choreographer.textController.editType = EditType.itDismissed;
|
||||
choreographer.textController.text = sourceText!;
|
||||
choreographer.textController.setSystemText(
|
||||
sourceText!,
|
||||
EditType.itDismissed,
|
||||
);
|
||||
}
|
||||
clear();
|
||||
dismissed = true;
|
||||
|
|
@ -273,7 +275,10 @@ class ITController {
|
|||
);
|
||||
} finally {
|
||||
choreographer.stopLoading();
|
||||
choreographer.textController.text = "";
|
||||
choreographer.textController.setSystemText(
|
||||
"",
|
||||
EditType.other,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,5 @@ enum EditType {
|
|||
itGold,
|
||||
itStart,
|
||||
itDismissed,
|
||||
other,
|
||||
}
|
||||
|
|
|
|||
24
lib/pangea/choreographer/utils/input_paste_listener.dart
Normal file
24
lib/pangea/choreographer/utils/input_paste_listener.dart
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluffychat/pangea/choreographer/enums/edit_type.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/igc/pangea_text_controller.dart';
|
||||
|
||||
class InputPasteListener {
|
||||
final PangeaTextController controller;
|
||||
final VoidCallback onPaste;
|
||||
|
||||
String _currentText = '';
|
||||
|
||||
InputPasteListener(
|
||||
this.controller,
|
||||
this.onPaste,
|
||||
) {
|
||||
controller.addListener(() {
|
||||
if (controller.editType != EditType.keyboard) return;
|
||||
final difference =
|
||||
controller.text.characters.length - _currentText.characters.length;
|
||||
if (difference.abs() > 1) onPaste();
|
||||
_currentText = controller.text;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -68,12 +68,11 @@ class ITFeedbackCardController extends State<ITFeedbackCard> {
|
|||
);
|
||||
})
|
||||
.catchError((e) => error = e)
|
||||
.whenComplete(
|
||||
() => setState(() {
|
||||
// isTranslating = false;
|
||||
isLoadingFeedback = false;
|
||||
}),
|
||||
);
|
||||
.whenComplete(() {
|
||||
if (mounted) {
|
||||
setState(() => isLoadingFeedback = false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue