Merge branch 'chat/header-islands'

# Conflicts:
#	app/tool/capture/README.md
This commit is contained in:
2026-11-07 02:50:13 +00:00
15 changed files with 353 additions and 201 deletions
@@ -98,7 +98,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
final label = _name;
// At phone widths the title and a named mode cannot both remain useful.
// Keep the mode's shield, whose semantic label and picker still name it.
final iconOnly = cupertino && MediaQuery.sizeOf(context).width < 600;
final iconOnly = MediaQuery.sizeOf(context).width < 600;
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
@@ -116,14 +116,19 @@ class _ChatModelControlState extends State<ChatModelControl> {
: widget.answeredBy.isNotEmpty
? widget.answeredBy
: '${backend.isEmpty ? 'opencode' : backend} default';
final content = Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
const SizedBox(width: 4),
Icon(cupertino ? CupertinoIcons.chevron_down : Icons.expand_more),
],
);
final compact = MediaQuery.sizeOf(context).width < 600;
final content = compact
? Icon(
cupertino ? CupertinoIcons.sparkles : Icons.auto_awesome_outlined,
)
: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: Text(label, overflow: TextOverflow.ellipsis)),
const SizedBox(width: 4),
Icon(cupertino ? CupertinoIcons.chevron_down : Icons.expand_more),
],
);
const key = Key('chat-model');
if (cupertino) {
return Semantics(
@@ -1,11 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/sessions/chat_adaptive.dart';
import '../../../ui/adaptive/segmented_bar.dart';
enum ChatSidebarMode { expanded, compact, hidden }
/// Pinned rather than overflowed: the list can always be restored from a pane.
class ChatSidebarButton extends StatelessWidget {
/// Native list-layout selector, also available in the chat actions menu.
class ChatSidebarButton extends StatelessWidget
implements SegmentedOverflowable {
const ChatSidebarButton({
super.key,
required this.mode,
@@ -14,6 +16,20 @@ class ChatSidebarButton extends StatelessWidget {
final ChatSidebarMode mode;
final ValueChanged<ChatSidebarMode> onChanged;
@override
SegmentedOverflowEntry get overflowEntry => SegmentedOverflowEntry(
label: 'Chat list layout',
icon: Icons.view_sidebar_outlined,
choices: [
for (final value in ChatSidebarMode.values)
SegmentedMenuChoice(
label: _label(value),
selected: value == mode,
onSelected: () => onChanged(value),
),
],
);
Future<void> _choose(BuildContext context) async {
final ChatSidebarMode? choice;
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../ui/sessions/chat_adaptive.dart';
/// The open conversation's bar: the app's [SegmentedBar] above the
@@ -9,7 +10,8 @@ import '../ui/sessions/chat_adaptive.dart';
///
/// From the leading edge: a round Back (only where the page can go back), a
/// pill with the conversation's title and folder that opens the chat's
/// information, and a pill holding [controls] (model and mode).
/// information, a selector island holding [controls] (model and mode),
/// then the Files action and a native More menu in a separate island.
class ChatThreadHeader extends StatelessWidget {
const ChatThreadHeader({
super.key,
@@ -19,6 +21,8 @@ class ChatThreadHeader extends StatelessWidget {
this.showBack = false,
this.onBack,
this.controls = const [],
this.actions = const [],
this.moreActions = const [],
this.backdrop,
});
@@ -34,6 +38,8 @@ class ChatThreadHeader extends StatelessWidget {
/// What Back does; null keeps the platform's stock action (pop the route).
final VoidCallback? onBack;
final List<Widget> controls;
final List<Widget> actions;
final List<Widget> moreActions;
/// Painted over the bar's scrim, under its pieces (the chat's colour).
final Widget? backdrop;
@@ -60,9 +66,49 @@ class ChatThreadHeader extends StatelessWidget {
onTitlePressed: onInfo,
titleSemanticLabel: 'Chat information',
titleKey: const Key('chat-info'),
actions: controls,
separateActionIslands: true,
actions: [
if (controls.isNotEmpty)
_ControlIsland(
key: const Key('chat-model-permission-island'),
children: controls,
),
if (actions.isNotEmpty || moreActions.isNotEmpty)
Row(
key: const Key('chat-actions-island'),
mainAxisSize: MainAxisSize.min,
children: [
...actions,
// Unknown action widgets retain their original behavior and stay
// visible; only the explicit overflow contract becomes a menu.
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
SegmentedMoreButton(
cupertino: cupertino,
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
],
),
],
),
],
bottomPadding: 16,
backdrop: backdrop,
);
}
}
/// Related selectors share the available width. Each remains a real control;
/// they never migrate into the unrelated actions menu.
class _ControlIsland extends StatelessWidget {
const _ControlIsland({super.key, required this.children});
final List<Widget> children;
@override
Widget build(BuildContext context) => Row(
mainAxisSize: MainAxisSize.min,
children: [for (final child in children) Flexible(child: child)],
);
}
@@ -15,7 +15,6 @@ import '../domain/chat_attachment_picker.dart';
import '../domain/chat_colors.dart';
import '../domain/chat_transcript.dart';
import '../ui/sessions/chat_adaptive.dart';
import 'chat_next_chat_button.dart';
import '../ui/sessions/chat_color_picker.dart';
import '../ui/sessions/session_actions.dart';
import '../ui/transcript/chat_markdown_view.dart';
@@ -103,8 +102,7 @@ class ChatThreadView extends StatefulWidget {
final ApiGateway gateway;
/// Opens the chat after this one in the list (wrapping to the first), from
/// the bar's Next chat button; null when there is no other chat to open.
/// Retained for existing callers; Next chat is no longer shown in the header.
final VoidCallback? onNextChat;
final List<Widget> paneControls;
final Widget? sidebarControl;
@@ -1326,12 +1324,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
: widget.showBackButton == true
? widget.onBack
: (inShellBar ? null : widget.onBack),
// Each control is its own action, so each pops in (and sinks) on its
// own. Natural width while the bar has room; past the title's share
// the model ellipsises, and the mode keeps its whole name until it
// would take more than half the pill. A session without a mode draws
// no mode control, so no empty pill is ever drawn.
controls: [
// Keep selectors in their own island before Files and the actions menu.
// Sidebar and pane actions retain their native overflow contracts.
actions: [
ChatBarAction(
label: 'Files',
identifier: 'chat-files-toggle',
@@ -1341,8 +1336,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
? CupertinoIcons.folder_fill
: CupertinoIcons.folder,
),
?widget.sidebarControl,
...widget.paneControls,
],
moreActions: [?widget.sidebarControl, ...widget.paneControls],
controls: [
if (hasModel)
ChatModelControl(
key: ValueKey<String>('chat-model-${widget.sessionId}'),
@@ -1353,8 +1349,6 @@ class _ChatThreadViewState extends State<ChatThreadView> {
answeredBy: answeredBy,
),
if (hasMode) _modeControl(),
if (widget.onNextChat case final next?)
ChatNextChatButton(key: const Key('chat-next'), onPressed: next),
],
);
}