ui: fold the composer to one line until it has focus

dsh-Go opens the input into two rows only while focused: the text above, the
model / mode / keys below, folding back when focus leaves. ComposerBox keeps
the field across the two layouts with a GlobalKey and animates the swap.

Model and thinking level are now one control (ModelPill shows "model · effort"
and the sheet offers the level after choosing a model); Build/Plan is a
separate ModeChip. The draft page uses the same box, with its project chip
above it. 0.3.15 (315).
This commit is contained in:
blumia committed 2026-11-21 17:47:04 +08:00
1 parent 7f2f454539
commit ea3b1f0f5e
8 files changed
+553 -430

No files matched your search

+100 -127
View File
@@ -11,6 +11,7 @@ import '../api/models.dart';
import '../state.dart';
import '../widgets/composer_attachment.dart';
import '../widgets/markdown_view.dart';
import '../widgets/composer_box.dart';
import '../widgets/model_controls.dart';
import '../widgets/slash_palette.dart';
import '../widgets/usage_ring.dart';
@@ -1331,13 +1332,6 @@ class _ChatScreenState extends State<ChatScreen> {
onPick: _pickSlash,
);
/// dsh-Go shows the model row while the input is in use; an empty, idle
/// composer leaves the space to the messages.
bool _showModelControls() =>
_inputFocus.hasFocus ||
_draftCtrl.text.trim().isNotEmpty ||
chat.running;
Widget _composer() {
final usage = chat.usageReading();
final scheme = Theme.of(context).colorScheme;
@@ -1345,128 +1339,107 @@ class _ChatScreenState extends State<ChatScreen> {
final slash = _slashMatches();
final slashRows = slash ?? const <SlashItem>[];
Widget body = Padding(
padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (_showModelControls()) ...[
ModelControlsBar(
app: widget.app,
model: chat.selectedModel ?? widget.session.model,
agent: chat.selectedAgent,
onModel: (m) => chat.switchModel(m),
onAgent: (a) => chat.switchAgent(a),
),
const SizedBox(height: 6),
],
if (_attachments.isNotEmpty) _attachmentTray(),
if (slash != null) ...[
KeyedSubtree(
key: const ValueKey('slash-palette'),
child: _slashPalette(slashRows),
),
const SizedBox(height: 6),
],
Container(
key: const ValueKey('composer-bar'),
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(26),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
_roundKey(
icon: Icons.attach_file,
label: '添加附件',
onTap: _pickFiles,
busy: _attaching,
),
const SizedBox(width: 4),
Expanded(
child: TextField(
controller: _draftCtrl,
focusNode: _inputFocus,
minLines: 1,
maxLines: 5,
keyboardType: TextInputType.multiline,
// While the palette is up, the keyboard's action key
// picks the highlighted row instead of writing a
// newline.
textInputAction: slash != null
? TextInputAction.send
: TextInputAction.newline,
onSubmitted: slash == null || slashRows.isEmpty
? null
: (_) => _pickSlash(
slashRows[_slashIndex.clamp(0, slashRows.length - 1)]),
onChanged: (v) {
chat.draft = v;
_slashIndex = 0;
if (_slashDismissed != null && v != _slashDismissed) {
_slashDismissed = null;
}
if (v.trimLeft().startsWith('/')) chat.ensureSlash();
setState(() {});
// A soft keyboard whose action key still writes a
// newline commits the highlighted row instead of
// leaving a stray blank line in the draft.
if (slash != null && v.endsWith('\n')) {
final trimmed = v.trimRight();
_draftCtrl.value = TextEditingValue(
text: trimmed,
selection:
TextSelection.collapsed(offset: trimmed.length),
);
chat.draft = trimmed;
final rows = _slashMatches() ?? const <SlashItem>[];
if (rows.isNotEmpty) {
_pickSlash(rows[_slashIndex.clamp(0, rows.length - 1)]);
}
}
},
style: const TextStyle(fontSize: 15, height: 1.45),
decoration: InputDecoration(
hintText: chat.running ? '生成中,仍可输入…' : '发消息…',
hintMaxLines: 1,
isDense: true,
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 8),
),
),
),
if (usage.$5)
InkWell(
onTap: () => _usageSheet(context),
borderRadius: BorderRadius.circular(20),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
UsageRing(pct: usage.$4, size: 16, accent: scheme.primary),
const SizedBox(width: 3),
Text('${usage.$4.round()}%',
style: TextStyle(fontSize: 12, color: scheme.onSurfaceVariant)),
],
),
),
),
const SizedBox(width: 2),
_roundKey(
icon: chat.running ? Icons.stop_rounded : Icons.arrow_upward_rounded,
label: chat.running ? '停止' : '发送',
filled: true,
enabled: chat.running || canSend,
onTap: chat.running ? chat.stop : _send,
),
],
),
padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (_attachments.isNotEmpty) _attachmentTray(),
if (slash != null) ...[
KeyedSubtree(
key: const ValueKey('slash-palette'),
child: _slashPalette(slashRows),
),
const SizedBox(height: 6),
],
),
);
ComposerBox(
controller: _draftCtrl,
focusNode: _inputFocus,
hint: chat.running ? '生成中,仍可输入…' : '发消息…',
maxLines: 5,
// While the palette is up, the keyboard's action key picks the
// highlighted row instead of writing a newline.
textInputAction:
slash != null ? TextInputAction.send : TextInputAction.newline,
onSubmitted: slash == null || slashRows.isEmpty
? null
: (_) => _pickSlash(
slashRows[_slashIndex.clamp(0, slashRows.length - 1)]),
onChanged: (v) {
chat.draft = v;
_slashIndex = 0;
if (_slashDismissed != null && v != _slashDismissed) {
_slashDismissed = null;
}
if (v.trimLeft().startsWith('/')) chat.ensureSlash();
setState(() {});
// A soft keyboard whose action key still writes a newline
// commits the highlighted row instead of leaving a stray blank
// line in the draft.
if (slash != null && v.endsWith('\n')) {
final trimmed = v.trimRight();
_draftCtrl.value = TextEditingValue(
text: trimmed,
selection: TextSelection.collapsed(offset: trimmed.length),
);
chat.draft = trimmed;
final rows = _slashMatches() ?? const <SlashItem>[];
if (rows.isNotEmpty) {
_pickSlash(rows[_slashIndex.clamp(0, rows.length - 1)]);
}
}
},
leading: _roundKey(
icon: Icons.attach_file,
label: '添加附件',
onTap: _pickFiles,
busy: _attaching,
),
model: ModelPill(
app: widget.app,
model: chat.selectedModel ?? widget.session.model,
onModel: (m) => chat.switchModel(m),
),
mode: ModeChip(
app: widget.app,
agent: chat.selectedAgent,
onAgent: (a) => chat.switchAgent(a),
),
accessory: usage.$5
? InkWell(
onTap: () => _usageSheet(context),
borderRadius: BorderRadius.circular(20),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
UsageRing(
pct: usage.$4,
size: 16,
accent: scheme.primary),
const SizedBox(width: 3),
Text('${usage.$4.round()}%',
style: TextStyle(
fontSize: 12,
color: scheme.onSurfaceVariant)),
],
),
),
)
: null,
trailing: _roundKey(
icon: chat.running
? Icons.stop_rounded
: Icons.arrow_upward_rounded,
label: chat.running ? '停止' : '发送',
filled: true,
enabled: chat.running || canSend,
onTap: chat.running ? chat.stop : _send,
),
),
],
),
);
// Always wrapped: re-parenting the field when the palette opens would
// drop its focus, and with it the characters typed after `/`.
return SafeArea(
+72 -97
View File
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
import '../api/models.dart';
import '../state.dart';
import '../widgets/composer_attachment.dart';
import '../widgets/composer_box.dart';
import '../widgets/model_controls.dart';
import '../widgets/slash_palette.dart';
import 'files_panel.dart';
@@ -244,16 +245,11 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
fontSize: 12.5, color: scheme.error),
),
),
ModelControlsBar(
app: widget.app,
model: draft.model,
agent: draft.agent,
leading: _projectChip(draft),
onModel: (m) => widget.app.updateDraftModel(m),
onAgent: (a) =>
widget.app.updateDraftModel(null, agent: a),
Align(
alignment: Alignment.centerLeft,
child: _projectChip(draft),
),
const SizedBox(height: 6),
const SizedBox(height: 4),
if (_attachments.isNotEmpty)
AttachmentTray(
items: _attachments,
@@ -305,68 +301,75 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
final sending = widget.app.sendingDraft;
final slash = _slashMatches();
final slashRows = slash ?? const <SlashItem>[];
Widget body = Container(
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(26),
Widget body = ComposerBox(
controller: _text,
focusNode: _inputFocus,
hint: '规划、构建或提问',
maxLines: 5,
textInputAction:
slash != null ? TextInputAction.send : TextInputAction.newline,
onSubmitted: slash == null || slashRows.isEmpty
? null
: (_) => _pickSlash(
slashRows[_slashIndex.clamp(0, slashRows.length - 1)]),
onChanged: (v) {
widget.app.updateDraftText(v);
_slashIndex = 0;
if (_slashDismissed != null && v != _slashDismissed) {
_slashDismissed = null;
}
if (v.trimLeft().startsWith('/')) _ensureSlash();
setState(() {});
if (slash != null && v.endsWith('\n')) {
final trimmed = v.trimRight();
_text.value = TextEditingValue(
text: trimmed,
selection: TextSelection.collapsed(offset: trimmed.length),
);
widget.app.updateDraftText(trimmed);
final rows = _slashMatches() ?? const <SlashItem>[];
if (rows.isNotEmpty) {
_pickSlash(rows[_slashIndex.clamp(0, rows.length - 1)]);
}
}
},
leading: _roundKey(
icon: Icons.attach_file,
label: '添加附件',
onTap: _pickFiles,
busy: _attaching,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
_roundKey(
icon: Icons.attach_file,
label: '添加附件',
onTap: _pickFiles,
busy: _attaching,
model: ModelPill(
app: widget.app,
model: _draft.model,
onModel: (m) => widget.app.updateDraftModel(m),
),
mode: ModeChip(
app: widget.app,
agent: _draft.agent,
onAgent: (a) => widget.app.updateDraftModel(null, agent: a),
),
trailing: InkWell(
borderRadius: BorderRadius.circular(18),
onTap: sending || !_canSend ? null : _send,
child: Container(
width: 36,
height: 36,
alignment: Alignment.center,
decoration: BoxDecoration(
color: _canSend || sending ? scheme.primary : scheme.surface,
shape: BoxShape.circle,
),
const SizedBox(width: 4),
Expanded(
child: TextField(
controller: _text,
focusNode: _inputFocus,
minLines: 1,
maxLines: 5,
keyboardType: TextInputType.multiline,
textInputAction: slash != null
? TextInputAction.send
: TextInputAction.newline,
onSubmitted: slash == null || slashRows.isEmpty
? null
: (_) => _pickSlash(
slashRows[_slashIndex.clamp(0, slashRows.length - 1)]),
onChanged: (v) {
widget.app.updateDraftText(v);
_slashIndex = 0;
if (_slashDismissed != null && v != _slashDismissed) {
_slashDismissed = null;
}
if (v.trimLeft().startsWith('/')) _ensureSlash();
setState(() {});
if (slash != null && v.endsWith('\n')) {
final trimmed = v.trimRight();
_text.value = TextEditingValue(
text: trimmed,
selection: TextSelection.collapsed(offset: trimmed.length),
);
widget.app.updateDraftText(trimmed);
final rows = _slashMatches() ?? const <SlashItem>[];
if (rows.isNotEmpty) {
_pickSlash(rows[_slashIndex.clamp(0, rows.length - 1)]);
}
}
},
decoration: const InputDecoration(
isCollapsed: true,
border: InputBorder.none,
hintText: '规划、构建或提问',
contentPadding: EdgeInsets.symmetric(vertical: 8),
),
),
),
const SizedBox(width: 4),
_sendKey(theme, sending),
],
child: sending
? SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2, color: scheme.onPrimary))
: Icon(Icons.arrow_upward,
size: 20,
color: _canSend ? scheme.onPrimary : theme.hintColor),
),
),
);
return Column(
@@ -437,34 +440,6 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
);
}
Widget _sendKey(ThemeData theme, bool sending) {
final scheme = theme.colorScheme;
return InkWell(
borderRadius: BorderRadius.circular(18),
onTap: sending || !_canSend ? null : _send,
child: Container(
width: 36,
height: 36,
alignment: Alignment.center,
decoration: BoxDecoration(
color: _canSend || sending
? scheme.primary
: scheme.surface,
shape: BoxShape.circle,
),
child: sending
? SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2, color: scheme.onPrimary))
: Icon(Icons.arrow_upward,
size: 20,
color: _canSend ? scheme.onPrimary : theme.hintColor),
),
);
}
Future<void> _pickProject() async {
final app = widget.app;
await app.refreshProjects();