feat: queue a message for the running turn, and fold the composer when the IME closes
- A send while a turn runs joins it (delivery "steer") on a short press; a long press offers steer or queue. Queue/steer prompts wait in the server's inbox and show as a pending bubble at the end of the transcript, with 改为排队/转为转向 and 撤回 (which puts the text back into the composer). The inbox is read on open and resume and kept current by the session.inbox.* events; delivery reloads the tail. - The send key is stop only while running with an empty draft; with text it sends (as dsh-Go does), leaving the long press for the delivery choice. - The composer also folds to one line when the phone's back gesture closes the keyboard while the field keeps focus: the page passes the keyboard height (a Scaffold strips the bottom inset from its body) and the composer treats a fall below half the peak as a dismissal. - The Build/Plan chip now opens a bottom sheet with icons, hints and a check, instead of a popup menu. - Tests: composer_box_test (focus opens, IME dismissal folds, typing reopens) and inbox_item_test (list items, enqueued events, delivery changes). - 0.3.16 (316).
This commit is contained in:
1 parent
ea3b1f0f5e
commit
1aa84a53e5
13 files changed
+655
-49
No files matched your search
@@ -9,6 +9,10 @@ class ComposerBox extends StatefulWidget {
|
||||
final FocusNode focusNode;
|
||||
final String hint;
|
||||
final int maxLines;
|
||||
|
||||
/// The soft keyboard's height, from the page (a Scaffold removes the bottom
|
||||
/// view inset from its body, so the composer cannot read it itself).
|
||||
final double keyboardInset;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
final TextInputAction textInputAction;
|
||||
@@ -40,6 +44,7 @@ class ComposerBox extends StatefulWidget {
|
||||
this.mode,
|
||||
this.accessory,
|
||||
this.maxLines = 5,
|
||||
this.keyboardInset = 0,
|
||||
this.onChanged,
|
||||
this.onSubmitted,
|
||||
this.textInputAction = TextInputAction.newline,
|
||||
@@ -55,6 +60,12 @@ class _ComposerBoxState extends State<ComposerBox> {
|
||||
final GlobalKey _fieldKey = GlobalKey();
|
||||
bool _open = false;
|
||||
|
||||
// The keyboard went down with the field still focused (the phone's back
|
||||
// gesture closes the IME without unfocusing). dsh-Go folds the composer in
|
||||
// that case too, so the same rule is kept here.
|
||||
bool _keyboardDown = false;
|
||||
double _keyboardPeak = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -68,8 +79,52 @@ class _ComposerBoxState extends State<ComposerBox> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ComposerBox oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.focusNode != widget.focusNode) {
|
||||
oldWidget.focusNode.removeListener(_onFocus);
|
||||
widget.focusNode.addListener(_onFocus);
|
||||
}
|
||||
if (oldWidget.keyboardInset != widget.keyboardInset) {
|
||||
_keyboardMoved(oldWidget.keyboardInset, widget.keyboardInset);
|
||||
// The build that follows reads this; no second one is needed.
|
||||
_open = widget.focusNode.hasFocus && !_keyboardDown;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
// A sheet over the page takes the keyboard for a moment; when the page is
|
||||
// current again, settle on where the composer should be.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _syncOpen());
|
||||
}
|
||||
|
||||
/// A keyboard rising clears "down"; falling to well under its peak means it
|
||||
/// was dismissed (a height change alone stays open).
|
||||
void _keyboardMoved(double before, double inset) {
|
||||
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
||||
if (inset > before) {
|
||||
_keyboardDown = false;
|
||||
if (inset > _keyboardPeak) _keyboardPeak = inset;
|
||||
} else if (inset < _keyboardPeak * 0.5) {
|
||||
_keyboardDown = true;
|
||||
_keyboardPeak = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void _onFocus() {
|
||||
final open = widget.focusNode.hasFocus;
|
||||
if (widget.focusNode.hasFocus) _keyboardDown = false;
|
||||
_syncOpen();
|
||||
}
|
||||
|
||||
void _syncOpen() {
|
||||
if (!mounted) return;
|
||||
// The model sheet (or any page over this one) takes focus for a moment:
|
||||
// leave the composer as it is until it is current again.
|
||||
if (!(ModalRoute.of(context)?.isCurrent ?? true)) return;
|
||||
final open = widget.focusNode.hasFocus && !_keyboardDown;
|
||||
if (open == _open) return;
|
||||
setState(() => _open = open);
|
||||
}
|
||||
|
||||
@@ -63,36 +63,60 @@ class ModeChip extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final current = agent.isEmpty ? _modes.first : agent;
|
||||
return PopupMenuButton<String>(
|
||||
tooltip: '模式',
|
||||
initialValue: current,
|
||||
onSelected: onAgent,
|
||||
itemBuilder: (_) {
|
||||
final known = [
|
||||
for (final a in app.agentList)
|
||||
if (a.mode == 'primary' && !a.hidden) a,
|
||||
];
|
||||
final ids = {
|
||||
..._modes,
|
||||
for (final a in known) a.id,
|
||||
};
|
||||
return [
|
||||
for (final id in ids)
|
||||
PopupMenuItem(
|
||||
value: id,
|
||||
child: Text(_label(id),
|
||||
style: TextStyle(
|
||||
fontWeight:
|
||||
id == current ? FontWeight.w700 : FontWeight.w400)),
|
||||
return _Pill(
|
||||
icon: Icons.tune,
|
||||
label: _label(current),
|
||||
onTap: () => _open(context, current),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _open(BuildContext context, String current) async {
|
||||
final known = [
|
||||
for (final a in app.agentList)
|
||||
if (a.mode == 'primary' && !a.hidden) a,
|
||||
];
|
||||
final ids = <String>{..._modes, for (final a in known) a.id};
|
||||
final names = {for (final a in known) a.id: a.name};
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final picked = await showModalBottomSheet<String>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
builder: (sheet) => SafeArea(
|
||||
top: false,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 4, 20, 8),
|
||||
child: Text('模式',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
];
|
||||
},
|
||||
child: _Pill(
|
||||
icon: Icons.tune,
|
||||
label: _label(current),
|
||||
onTap: null,
|
||||
for (final id in ids)
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
id == 'plan' ? Icons.map_outlined : Icons.construction_outlined,
|
||||
color: id == current ? scheme.primary : null,
|
||||
),
|
||||
title: Text(
|
||||
names[id]?.isNotEmpty == true ? names[id]! : _label(id),
|
||||
style: TextStyle(
|
||||
fontWeight: id == current ? FontWeight.w700 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
subtitle: Text(id == 'plan' ? '先规划,不改动文件' : '直接构建',
|
||||
style: const TextStyle(fontSize: 12)),
|
||||
trailing: id == current
|
||||
? Icon(Icons.check, size: 20, color: scheme.primary)
|
||||
: null,
|
||||
onTap: () => Navigator.pop(sheet, id),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (picked != null && picked != current) onAgent(picked);
|
||||
}
|
||||
|
||||
static String _label(String id) =>
|
||||
|
||||
Reference in new issue
Block a user