cf9f71f27c
Dismissed shell runs leave the transcript and fold into a "N commands" chip in the footer of the first answer at or after each run (the last answer for newer runs, or a row of its own without any answer). The chip opens the turn sheet (wide) or a full-screen page (narrow) listing the commands; each opens its output read-only with Copy output, Send to agent and Restore. On a wide conversation the answer's Copy button moves out of the footer into a 48 px gutter left of the reading column (chatCopyGutter), shown on hover or focus on desktops and always on touch; narrow widths keep it in the footer.
111 lines
3.4 KiB
Dart
111 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../ui/adaptive/platform.dart';
|
|
|
|
/// The width of the strip left of the reading column that an answer row
|
|
/// draws its Copy button in (`chatCopyGutter`); 0 when there is no room, and
|
|
/// Copy stays in the answer's footer.
|
|
class ChatCopyGutter extends InheritedWidget {
|
|
const ChatCopyGutter({super.key, required this.width, required super.child});
|
|
|
|
final double width;
|
|
|
|
static double of(BuildContext context) =>
|
|
context.dependOnInheritedWidgetOfExactType<ChatCopyGutter>()?.width ?? 0;
|
|
|
|
@override
|
|
bool updateShouldNotify(ChatCopyGutter oldWidget) => width != oldWidget.width;
|
|
}
|
|
|
|
/// The transcript's [children] when the list starts [gutter] left of the
|
|
/// reading column: every child except the transcript [rows] (which inset
|
|
/// themselves) is inset past the gutter, so it keeps to the column.
|
|
List<Widget> chatCopyGutterInset(
|
|
double gutter,
|
|
List<Widget> rows,
|
|
List<Widget> children,
|
|
) {
|
|
if (gutter <= 0) return children;
|
|
final own = Set<Widget>.identity()..addAll(rows);
|
|
return [
|
|
for (final child in children)
|
|
if (own.contains(child))
|
|
child
|
|
else
|
|
Padding(
|
|
key: child.key,
|
|
padding: EdgeInsets.only(left: gutter),
|
|
child: child,
|
|
),
|
|
];
|
|
}
|
|
|
|
/// An answer with its Copy button in the gutter to its left, bottom-aligned
|
|
/// with the answer's footer row. On a desktop the button shows while the
|
|
/// pointer is over the answer or the button has focus; it stays in the
|
|
/// focus order and the semantics tree when hidden. Touch platforms always
|
|
/// show it.
|
|
class ChatCopyGutterRow extends StatefulWidget {
|
|
const ChatCopyGutterRow({
|
|
super.key,
|
|
required this.width,
|
|
required this.copy,
|
|
required this.child,
|
|
});
|
|
|
|
final double width;
|
|
|
|
/// The Copy button, or null when the answer has nothing to copy yet.
|
|
final Widget? copy;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<ChatCopyGutterRow> createState() => _ChatCopyGutterRowState();
|
|
}
|
|
|
|
class _ChatCopyGutterRowState extends State<ChatCopyGutterRow> {
|
|
bool _hovered = false;
|
|
bool _focused = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final hover = prefersCompactHitTargets(context);
|
|
final copy = widget.copy;
|
|
final row = Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
SizedBox(
|
|
key: const Key('chat-copy-gutter'),
|
|
width: widget.width,
|
|
child: copy == null
|
|
? null
|
|
: Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Focus(
|
|
canRequestFocus: false,
|
|
skipTraversal: true,
|
|
onFocusChange: (focused) =>
|
|
setState(() => _focused = focused),
|
|
child: AnimatedOpacity(
|
|
key: const Key('chat-copy-gutter-visibility'),
|
|
opacity: !hover || _hovered || _focused ? 1 : 0,
|
|
duration: const Duration(milliseconds: 120),
|
|
alwaysIncludeSemantics: true,
|
|
child: copy,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Flexible(child: widget.child),
|
|
],
|
|
);
|
|
if (!hover || copy == null) return row;
|
|
return MouseRegion(
|
|
onEnter: (_) => setState(() => _hovered = true),
|
|
onExit: (_) => setState(() => _hovered = false),
|
|
child: row,
|
|
);
|
|
}
|
|
}
|