Skip to content

Commit

Permalink
feat: send msg via ctrl+enter (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Jul 16, 2024
1 parent ee4657d commit 7aebb88
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
17 changes: 17 additions & 0 deletions lib/view/page/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:dart_openai/dart_openai.dart';
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
//import 'package:flutter_tiktoken/flutter_tiktoken.dart';
import 'package:gpt_box/data/model/chat/history/share.dart';
import 'package:gpt_box/core/route/page.dart';
Expand Down Expand Up @@ -70,6 +71,7 @@ class _HomePageState extends State<HomePage>
_refreshTimeTimer?.cancel();
_chatScrollCtrl.dispose();
_historyScrollCtrl.dispose();
_keyboardSendListener?.dispose();
super.dispose();
}

Expand Down Expand Up @@ -113,6 +115,7 @@ class _HomePageState extends State<HomePage>
/// - Init help uses [l10n] to gen msg, so [l10n] must be ready
/// - [l10n] is ready after first layout
_switchChat();
_listenKeyboard();
_historyRN.notify();
_removeDuplicateHistory(context);

Expand All @@ -125,6 +128,20 @@ class _HomePageState extends State<HomePage>
}
}

void _listenKeyboard() {
_keyboardSendListener = KeyboardCtrlListener(
key: PhysicalKeyboardKey.enter,
callback: () {
// If the current page is not chat, do nothing
if (ModalRoute.of(context)?.isCurrent != true) return false;

if (_inputCtrl.text.isEmpty) return false;
_onCreateRequest(context, _curChatId);
return true;
},
);
}

Future<void> _initUrlScheme() async {
if (isWeb) {
final uri = await _appLink.getInitialLink();
Expand Down
2 changes: 2 additions & 0 deletions lib/view/page/home/var.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ const _durationShort = Durations.short4;
const _durationMedium = Durations.medium1;

final _chatFabAutoHideKey = GlobalKey<AutoHideState>();

KeyboardCtrlListener? _keyboardSendListener;
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.0.68"
resolved-ref: "489ac2d0abf52ee09e5a42418f976558bd51a625"
ref: "v1.0.70"
resolved-ref: "1b92ba4148e709215e30cd9696652079b25fd950"
url: "https://github.com/lppcg/fl_lib"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies:
fl_lib:
git:
url: https://github.com/lppcg/fl_lib
ref: v1.0.68
ref: v1.0.70
# path: ../fl_lib

dev_dependencies:
Expand Down

0 comments on commit 7aebb88

Please sign in to comment.