mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 12:29:04 +08:00
send when left shift key is not pressed
This commit is contained in:
parent
92fada0c8e
commit
c9ce5233f5
@ -54,16 +54,14 @@ class ChatPage extends StatelessWidget implements PageShape {
|
||||
children: [
|
||||
LayoutBuilder(builder: (context, constraints) {
|
||||
final chat = DashChat(
|
||||
onSend: (chatMsg) {
|
||||
chatModel.send(chatMsg);
|
||||
chatModel.inputNode.requestFocus();
|
||||
},
|
||||
onSend: chatModel.send,
|
||||
currentUser: chatModel.me,
|
||||
messages:
|
||||
chatModel.messages[chatModel.currentID]?.chatMessages ??
|
||||
[],
|
||||
inputOptions: InputOptions(
|
||||
focusNode: chatModel.inputNode,
|
||||
textController: chatModel.textController,
|
||||
inputTextStyle: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme.titleLarge?.color),
|
||||
|
@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:dash_chat_2/dash_chat_2.dart';
|
||||
import 'package:draggable_float_widget/draggable_float_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -42,6 +43,14 @@ class ChatModel with ChangeNotifier {
|
||||
|
||||
Rx<VoiceCallStatus> get voiceCallStatus => _voiceCallStatus;
|
||||
|
||||
TextEditingController textController = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
textController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
final ChatUser me = ChatUser(
|
||||
id: "",
|
||||
firstName: translate("Me"),
|
||||
@ -75,12 +84,36 @@ class ChatModel with ChangeNotifier {
|
||||
final WeakReference<FFI> parent;
|
||||
|
||||
late final SessionID sessionId;
|
||||
late FocusNode inputNode;
|
||||
|
||||
ChatModel(this.parent) {
|
||||
sessionId = parent.target!.sessionId;
|
||||
inputNode = FocusNode(
|
||||
onKey: (node, event) {
|
||||
bool isShiftPressed = event.isKeyPressed(LogicalKeyboardKey.shiftLeft);
|
||||
bool isEnterPressed = event.isKeyPressed(LogicalKeyboardKey.enter);
|
||||
|
||||
String trimmedText = textController.text.trim();
|
||||
|
||||
// don't send empty message
|
||||
if (trimmedText.isEmpty) {
|
||||
textController.text = trimmedText;
|
||||
}
|
||||
|
||||
FocusNode inputNode = FocusNode();
|
||||
if (isEnterPressed && !isShiftPressed) {
|
||||
final ChatMessage message = ChatMessage(
|
||||
text: trimmedText,
|
||||
user: me,
|
||||
createdAt: DateTime.now(),
|
||||
);
|
||||
send(message);
|
||||
textController.text = "";
|
||||
}
|
||||
|
||||
return KeyEventResult.ignored;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ChatUser get currentUser {
|
||||
final user = messages[currentID]?.chatUser;
|
||||
@ -313,6 +346,7 @@ class ChatModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
inputNode.requestFocus();
|
||||
}
|
||||
|
||||
close() {
|
||||
|
Loading…
Reference in New Issue
Block a user