Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send msg via ctrl+enter #90

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading