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:
1 parent
7f2f454539
commit
ea3b1f0f5e
8 files changed
+553
-430
No files matched your search
+100
-127
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user