- source strings are English again; Chinese comes from lib/l10n/zh.dart through tr()/trArgs() and AppText, and a language without a table (Spanish, ...) reads English instead of Chinese - server and user data (titles, messages, file names, notes, task names) is drawn with plain Text, so it is never looked up in the table - SelectionArea moved from the whole message list to the messages, the answer text, an opened tool call's details and the turn footer; status lines and folded tool rows no longer start a selection - a message the transcript does not know (its start event was lost while the stream was down) fetches the tail once, so a turn continued from another client comes in with its prompt - bump to 0.5.3
197 lines
7.3 KiB
Dart
197 lines
7.3 KiB
Dart
// The `/` palette above a composer, shared by the chat and the new-session
|
|
// draft: commands and skills of one directory, filtered as the name is typed.
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../state.dart';
|
|
import '../l10n.dart';
|
|
|
|
const _slashLabels = {
|
|
'compact': 'Compact',
|
|
'init': 'Init',
|
|
'review': 'Review',
|
|
'goal': 'Goal',
|
|
'new-extension': 'New extension',
|
|
'permission': 'Permission',
|
|
'plan': 'Plans',
|
|
'feedback': 'Feedback',
|
|
};
|
|
|
|
String? slashLabel(SlashItem item) =>
|
|
item.skill ? null : _slashLabels[item.name];
|
|
|
|
/// Rows for a draft, or null when the palette should stay closed. It stays
|
|
/// up while only the command name is typed and closes once an argument
|
|
/// starts, unless the same text was dismissed with Esc.
|
|
List<SlashItem>? matchSlashItems({
|
|
required List<SlashItem> items,
|
|
required String text,
|
|
String? dismissed,
|
|
}) {
|
|
if (dismissed == text) return null;
|
|
final trimmed = text.trimLeft();
|
|
if (!trimmed.startsWith('/')) return null;
|
|
if (trimmed.length > 1 && RegExp(r'\s').hasMatch(trimmed.substring(1))) {
|
|
return null;
|
|
}
|
|
final query = trimmed.substring(1).toLowerCase().trim();
|
|
if (query.isEmpty) return items;
|
|
bool hit(SlashItem item) {
|
|
final label = slashLabel(item) ?? '';
|
|
return item.name.toLowerCase().contains(query) ||
|
|
label.toLowerCase().contains(query) ||
|
|
item.description.toLowerCase().contains(query);
|
|
}
|
|
|
|
return items.where(hit).toList()
|
|
..sort((a, b) {
|
|
final aPrefix = a.name.toLowerCase().startsWith(query) ? 0 : 1;
|
|
final bPrefix = b.name.toLowerCase().startsWith(query) ? 0 : 1;
|
|
if (aPrefix != bPrefix) return aPrefix - bPrefix;
|
|
if (a.skill != b.skill) return a.skill ? 1 : -1;
|
|
return a.name.compareTo(b.name);
|
|
});
|
|
}
|
|
|
|
/// The panel itself: rows with an icon, the command and its description.
|
|
class SlashPalette extends StatelessWidget {
|
|
final List<SlashItem> items;
|
|
final int index;
|
|
final bool loading;
|
|
final ValueChanged<SlashItem> onPick;
|
|
|
|
const SlashPalette({
|
|
super.key,
|
|
required this.items,
|
|
required this.index,
|
|
required this.loading,
|
|
required this.onPick,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
final selected = items.isEmpty ? 0 : index.clamp(0, items.length - 1);
|
|
Widget row(IconData icon, String title, String subtitle) => Padding(
|
|
padding: const EdgeInsets.fromLTRB(14, 14, 14, 14),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 32,
|
|
child: Icon(icon, size: 20, color: scheme.onSurfaceVariant),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(title,
|
|
style:
|
|
TextStyle(fontSize: 14, color: scheme.onSurface)),
|
|
if (subtitle.isNotEmpty)
|
|
Text(subtitle,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: scheme.onSurfaceVariant)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return Container(
|
|
constraints: const BoxConstraints(maxHeight: 56 * 5.5),
|
|
clipBehavior: Clip.antiAlias,
|
|
decoration: BoxDecoration(
|
|
color: scheme.surfaceContainerHigh,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: scheme.outlineVariant.withValues(alpha: 0.6)),
|
|
),
|
|
child: items.isEmpty
|
|
? (loading
|
|
? const Padding(
|
|
padding: EdgeInsets.all(18),
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2)),
|
|
),
|
|
)
|
|
: row(Icons.search_off, 'No commands available', 'This directory has no commands or skills yet'))
|
|
: ListView.builder(
|
|
shrinkWrap: true,
|
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 6),
|
|
itemCount: items.length,
|
|
itemBuilder: (context, i) {
|
|
final item = items[i];
|
|
final label = slashLabel(item);
|
|
final isSelected = i == selected;
|
|
return InkWell(
|
|
borderRadius: BorderRadius.circular(14),
|
|
onTap: () => onPick(item),
|
|
child: Container(
|
|
height: 56,
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? scheme.primary.withValues(alpha: 0.10)
|
|
: null,
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 32,
|
|
child: Icon(
|
|
item.skill
|
|
? Icons.extension_outlined
|
|
: Icons.terminal,
|
|
size: 20,
|
|
color: scheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
AppText('/${item.name}',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
color: scheme.onSurface)),
|
|
if (label != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 6),
|
|
child: AppText(label,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: scheme.onSurfaceVariant)),
|
|
),
|
|
],
|
|
),
|
|
if (item.description.isNotEmpty)
|
|
Text(item.description,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: scheme.onSurfaceVariant)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|