Merge branch 'main' into ws-files-panel
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
part of 'screen.dart';
|
||||
|
||||
/// How many chats the visit remembers for Ctrl+Tab over a single pane.
|
||||
const chatRecentSessionLimit = 8;
|
||||
|
||||
/// Keys the Chat destination answers from anywhere in it, also while the
|
||||
/// sidebar or a toolbar owns focus: a bare `/` puts the keyboard in the open
|
||||
/// chat's composer, and Ctrl+Tab over a single pane returns to the chat shown
|
||||
/// before it (and back again). Both are handled before the focus tree, like
|
||||
/// the workspace's pane cycling, and leave other destinations, popups,
|
||||
/// dialogs and any focused text field alone.
|
||||
mixin _ChatScreenKeys on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
void _open(JsonMap session, {bool focusComposer});
|
||||
|
||||
/// The chats this visit has shown in the workspace, most recent first; the
|
||||
/// active one leads it. In memory only: a reopened app starts afresh.
|
||||
final List<String> _recentSessions = [];
|
||||
|
||||
/// Moves the active pane's chat to the front. Called on every workspace
|
||||
/// change, including a restored layout, so the chat opened before the
|
||||
/// current one is always the second entry.
|
||||
@override
|
||||
void _noteRecentSession() {
|
||||
final id = _workspace.activePane?.sessionId;
|
||||
if (id == null || id.isEmpty || _recentSessions.firstOrNull == id) return;
|
||||
_recentSessions
|
||||
..remove(id)
|
||||
..insert(0, id);
|
||||
if (_recentSessions.length > chatRecentSessionLimit) {
|
||||
_recentSessions.removeLast();
|
||||
}
|
||||
}
|
||||
|
||||
/// Drops [id]: a closed chat, or one `/new` moved to a fresh session.
|
||||
void _forgetRecentSession(String id) => _recentSessions.remove(id);
|
||||
|
||||
/// Drops every remembered chat: ids belong to one server.
|
||||
@override
|
||||
void _forgetRecentSessions() => _recentSessions.clear();
|
||||
|
||||
/// Over a single pane, opens the chat shown before the active one with its
|
||||
/// composer focused; false when this visit has shown no other chat.
|
||||
@override
|
||||
bool _toggleRecentChat() {
|
||||
final current = _workspace.activePane?.sessionId;
|
||||
final previous = _recentSessions
|
||||
.where((id) => id != current)
|
||||
.firstOrNull;
|
||||
if (previous == null) return false;
|
||||
_open(_rowFor(previous) ?? {'id': previous}, focusComposer: true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Whether the shown destination is Chat with no popup, dialog or other
|
||||
/// route over it, so a key pressed now is meant for the open chat.
|
||||
@override
|
||||
bool _chatOwnsKeyboard() {
|
||||
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
|
||||
if (destination != null && destination != AppDestination.chat) return false;
|
||||
final focusContext = FocusManager.instance.primaryFocus?.context;
|
||||
final route = focusContext == null
|
||||
? ModalRoute.of(context)
|
||||
: ModalRoute.of(focusContext);
|
||||
return route is! PopupRoute && (route == null || route.isCurrent);
|
||||
}
|
||||
|
||||
/// A bare `/` typed outside any text field focuses the active chat's
|
||||
/// composer. The composer takes focus after this frame (see
|
||||
/// [ChatComposerFocusRequests]), once the host has finished delivering the
|
||||
/// keystroke, so the slash itself is not typed into it. Inside a text field
|
||||
/// (the composer, a dialog's field) `/` stays an ordinary character.
|
||||
bool _slashFocusKey(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (event is! KeyDownEvent ||
|
||||
event.character != '/' ||
|
||||
keyboard.isControlPressed ||
|
||||
keyboard.isMetaPressed ||
|
||||
keyboard.isAltPressed ||
|
||||
!_workspaceVisible) {
|
||||
return false;
|
||||
}
|
||||
final id = _workspace.activePane?.sessionId;
|
||||
if (id == null || _textFieldHasFocus() || !_chatOwnsKeyboard()) {
|
||||
return false;
|
||||
}
|
||||
_composerFocus.request(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Whether an editable text control holds focus, wherever it is.
|
||||
bool _textFieldHasFocus() {
|
||||
final context = FocusManager.instance.primaryFocus?.context;
|
||||
final editable = context?.findAncestorWidgetOfExactType<EditableText>();
|
||||
return editable != null && !editable.readOnly;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,10 @@ part of 'screen.dart';
|
||||
mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
Map<String, JsonMap> get _openedSessions;
|
||||
ChatComposerFocusRequests get _composerFocus;
|
||||
bool _chatOwnsKeyboard();
|
||||
bool _toggleRecentChat();
|
||||
void _noteRecentSession();
|
||||
void _forgetRecentSessions();
|
||||
JsonMap? _rowFor(String id);
|
||||
void _back();
|
||||
bool get _pageOpen;
|
||||
@@ -89,6 +93,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
_workspaceBinding = null;
|
||||
if (_workspaceScope != null && scope != _workspaceScope) {
|
||||
_workspace.restoreLayout(ChatWorkspaceSnapshot.fromLayout(null, null)!);
|
||||
_forgetRecentSessions();
|
||||
_workspaceVisible = false;
|
||||
_usedWorkspace = true;
|
||||
_sidebarMode = ChatSidebarMode.expanded;
|
||||
@@ -111,7 +116,9 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
String _workspaceSignature = '';
|
||||
|
||||
/// Ctrl+Tab cycles retained panes even when the sidebar or toolbar owns
|
||||
/// focus. Command+Tab stays with the operating system's application switcher.
|
||||
/// focus. Over a single pane it swaps in the chat shown before this one
|
||||
/// instead, and back again (see [_toggleRecentChat]). Command+Tab stays
|
||||
/// with the operating system's application switcher.
|
||||
bool _cycleChatKey(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (event is! KeyDownEvent ||
|
||||
@@ -120,19 +127,12 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
keyboard.isMetaPressed ||
|
||||
keyboard.isAltPressed ||
|
||||
!_workspaceVisible ||
|
||||
_workspace.paneCount == 0) {
|
||||
return false;
|
||||
}
|
||||
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
|
||||
if (destination != null && destination != AppDestination.chat) return false;
|
||||
final focusContext = FocusManager.instance.primaryFocus?.context;
|
||||
final route = focusContext == null
|
||||
? ModalRoute.of(context)
|
||||
: ModalRoute.of(focusContext);
|
||||
if (route is PopupRoute || (route != null && !route.isCurrent)) {
|
||||
_workspace.paneCount == 0 ||
|
||||
!_chatOwnsKeyboard()) {
|
||||
return false;
|
||||
}
|
||||
final panes = _workspace.panes;
|
||||
if (panes.length == 1 && _toggleRecentChat()) return true;
|
||||
final active = panes.indexWhere(
|
||||
(pane) => pane.id == _workspace.activePaneId,
|
||||
);
|
||||
@@ -156,7 +156,9 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
}
|
||||
|
||||
void _workspaceChanged() {
|
||||
if (!mounted || _workspaceBinding?.isRestoring == true) return;
|
||||
if (!mounted) return;
|
||||
_noteRecentSession();
|
||||
if (_workspaceBinding?.isRestoring == true) return;
|
||||
final signature =
|
||||
'${_workspace.activePaneId}:${_workspace.panes.map((p) => '${p.id}=${p.sessionId}').join(',')}';
|
||||
if (_workspaceSignature == signature) return;
|
||||
|
||||
@@ -27,6 +27,8 @@ import '../../../ui/adaptive/pop_entrance.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
import 'composer_focus_request.dart';
|
||||
import 'composer_focus_restore.dart';
|
||||
import 'composer_focus_ring.dart';
|
||||
import '../ui/sessions/chat_color_palette.dart';
|
||||
|
||||
/// The composer's placeholder when the chat names no working directory.
|
||||
const String chatComposerPlaceholder = 'Message the agent';
|
||||
@@ -49,6 +51,22 @@ bool chatEnterSends([TargetPlatform? platform]) {
|
||||
return target != TargetPlatform.android && target != TargetPlatform.iOS;
|
||||
}
|
||||
|
||||
/// The composer's gap above the bottom of the window (or its bottom safe
|
||||
/// area) on a phone, where it sits just over the keyboard or home indicator.
|
||||
const double kChatComposerBottomMargin = 12;
|
||||
|
||||
/// The same gap on a desktop host (native or a desktop browser), whose
|
||||
/// window's bottom edge is a hard frame under a pointer: the composer keeps
|
||||
/// more room from it so it does not read as stuck to the edge.
|
||||
const double kChatComposerDesktopBottomMargin = 24;
|
||||
|
||||
/// The composer's bottom gap on [platform] (the running host by default),
|
||||
/// split between phones and desktops as [chatEnterSends] is.
|
||||
double chatComposerBottomMargin([TargetPlatform? platform]) =>
|
||||
chatEnterSends(platform)
|
||||
? kChatComposerDesktopBottomMargin
|
||||
: kChatComposerBottomMargin;
|
||||
|
||||
/// The single primary control's words while a turn is and is not running.
|
||||
const String chatSendLabel = 'Send';
|
||||
const String chatStopLabel = 'Stop';
|
||||
@@ -103,8 +121,13 @@ class ChatComposerBar extends StatefulWidget {
|
||||
this.placeholder = chatComposerPlaceholder,
|
||||
this.enterSends,
|
||||
this.images,
|
||||
this.chatColor,
|
||||
});
|
||||
|
||||
/// The chat's colour name (see `chatSessionColor`), the accent of the
|
||||
/// field's focus ring; null takes the host's primary colour.
|
||||
final String? chatColor;
|
||||
|
||||
/// The transcript's image cache, told about uploaded files so the sent turn
|
||||
/// shows them without a round trip.
|
||||
final ChatAttachmentImages? images;
|
||||
@@ -717,7 +740,12 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
constraints: const BoxConstraints(maxWidth: kChatReadingWidth),
|
||||
child: Padding(
|
||||
key: const Key('chat-composer'),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 12),
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
16,
|
||||
8,
|
||||
16,
|
||||
chatComposerBottomMargin(),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@@ -797,22 +825,39 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
);
|
||||
}
|
||||
|
||||
static const OutlinedBorder _pillShape = RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(28)),
|
||||
);
|
||||
|
||||
/// The field and its controls in one frosted-glass surface floating over
|
||||
/// the transcript, so the composer reads as a single input rather than a
|
||||
/// row of separate controls, and the conversation shows through it.
|
||||
Widget _pill(BuildContext context, bool cupertino, Widget child) => GlassPill(
|
||||
key: const Key('chat-composer-pill'),
|
||||
cupertino: cupertino,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(28)),
|
||||
),
|
||||
// The end controls keep the same gap from the pill's sides as from its
|
||||
// bottom (and its top while the field is one line).
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(GlassBarMetrics.fieldEdgeGap),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
/// row of separate controls, and the conversation shows through it. While
|
||||
/// the field has focus the pill's edge takes the chat's accent.
|
||||
Widget _pill(BuildContext context, bool cupertino, Widget child) =>
|
||||
ComposerFocusRing(
|
||||
focus: _focus,
|
||||
accent: _accent(context, cupertino),
|
||||
shape: _pillShape,
|
||||
child: GlassPill(
|
||||
key: const Key('chat-composer-pill'),
|
||||
cupertino: cupertino,
|
||||
shape: _pillShape,
|
||||
// The end controls keep the same gap from the pill's sides as from
|
||||
// its bottom (and its top while the field is one line).
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(GlassBarMetrics.fieldEdgeGap),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// The chat's accent: its own colour's shade for this host and brightness,
|
||||
/// else the host's primary colour.
|
||||
Color _accent(BuildContext context, bool cupertino) =>
|
||||
chatColorShade(context, widget.chatColor) ??
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary);
|
||||
|
||||
/// The attach control: a host button that opens the picker, disabled when the
|
||||
/// host has no picker or one prompt is already awaiting its reply.
|
||||
|
||||
@@ -1056,6 +1056,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
placeholder: chatComposerPlaceholderFor(
|
||||
'${widget.session?['directory'] ?? ''}',
|
||||
),
|
||||
chatColor: chatSessionColor(widget.session),
|
||||
backgroundTasks: ChatBackgroundTasks(
|
||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||
gateway: widget.gateway,
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// The composer's focus indication: a thin ring in the chat's accent colour
|
||||
/// along the pill's edge and a soft glow of the same colour outside it, so
|
||||
/// a focused field shows as such without relying on its caret alone. Both
|
||||
/// fade in and out with focus; at rest unfocused nothing visible is drawn.
|
||||
///
|
||||
/// The accent is the chat's own colour (its highlight in the list) when it
|
||||
/// has one, else the host's primary colour, never the pill's background: the
|
||||
/// ring is translucent so the same tint stays subtle on a light and a dark
|
||||
/// pill.
|
||||
class ComposerFocusRing extends StatelessWidget {
|
||||
const ComposerFocusRing({
|
||||
super.key,
|
||||
required this.focus,
|
||||
required this.accent,
|
||||
required this.shape,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
/// The field's focus node; the ring follows its [FocusNode.hasFocus].
|
||||
final FocusNode focus;
|
||||
|
||||
/// The chat's accent, at full opacity; the ring and glow fade it.
|
||||
final Color accent;
|
||||
|
||||
/// The pill's shape, so the ring hugs its edge.
|
||||
final OutlinedBorder shape;
|
||||
final Widget child;
|
||||
|
||||
/// How long the ring takes to appear or fade.
|
||||
static const Duration duration = Duration(milliseconds: 160);
|
||||
|
||||
/// The ring's stroke, drawn just inside the pill's edge over its hairline.
|
||||
static const double ringWidth = 1.5;
|
||||
|
||||
/// The accent's opacity in the ring while focused.
|
||||
static const double ringOpacity = 0.6;
|
||||
|
||||
/// The accent's opacity in the glow while focused.
|
||||
static const double glowOpacity = 0.18;
|
||||
|
||||
/// The glow's blur radius; it spreads [glowSpread] past the pill first.
|
||||
static const double glowBlur = 12;
|
||||
static const double glowSpread = 1;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListenableBuilder(
|
||||
listenable: focus,
|
||||
child: child,
|
||||
builder: (context, child) {
|
||||
final focused = focus.hasFocus;
|
||||
// Both decorations keep the same shape, shadow and stroke while only
|
||||
// their colours change, so the container lerps them into one fade.
|
||||
return AnimatedContainer(
|
||||
key: const Key('chat-composer-focus-ring'),
|
||||
duration: duration,
|
||||
curve: Curves.easeOutCubic,
|
||||
decoration: ShapeDecoration(
|
||||
shape: shape,
|
||||
shadows: [
|
||||
BoxShadow(
|
||||
color: accent.withValues(alpha: focused ? glowOpacity : 0),
|
||||
blurRadius: glowBlur,
|
||||
spreadRadius: glowSpread,
|
||||
),
|
||||
],
|
||||
),
|
||||
// Over the child: the pill's fill would otherwise cover the ring.
|
||||
foregroundDecoration: ShapeDecoration(
|
||||
shape: shape.copyWith(
|
||||
side: BorderSide(
|
||||
color: accent.withValues(alpha: focused ? ringOpacity : 0),
|
||||
width: ringWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import 'ui/sessions/chat_sessions_body.dart';
|
||||
import 'ui/sessions/chat_sessions_controller.dart';
|
||||
import 'ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
part 'chat_screen_keys.dart';
|
||||
part 'chat_screen_workspace.dart';
|
||||
|
||||
/// The Chat destination's list/detail switch.
|
||||
@@ -73,7 +74,8 @@ class ChatScreen extends StatefulWidget {
|
||||
State<ChatScreen> createState() => _ChatScreenState();
|
||||
}
|
||||
|
||||
class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
class _ChatScreenState extends State<ChatScreen>
|
||||
with _ChatScreenWorkspace, _ChatScreenKeys {
|
||||
/// The list's controller, shared with the mounted list screen. The list
|
||||
/// screen refreshes it on mount and swaps its repository when the socket is
|
||||
/// replaced; this destination lists created rows and re-reads after a
|
||||
@@ -141,10 +143,12 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
_workspace.open(initial);
|
||||
_workspaceVisible = true;
|
||||
_publishedWorkspaceSession = initial;
|
||||
_noteRecentSession();
|
||||
}
|
||||
_workspace.addListener(_workspaceChanged);
|
||||
_bindWorkspacePersistence();
|
||||
HardwareKeyboard.instance.addHandler(_cycleChatKey);
|
||||
HardwareKeyboard.instance.addHandler(_slashFocusKey);
|
||||
// Seen from now on, so the press that chooses the first chat counts.
|
||||
LastPointerKind.instance;
|
||||
_sessions.addListener(_nextChanged);
|
||||
@@ -201,6 +205,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
void _openBySelection(JsonMap session) =>
|
||||
_open(session, focusComposer: chatSelectionFocusesComposer(session));
|
||||
|
||||
@override
|
||||
void _open(JsonMap session, {bool focusComposer = false}) {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
if (id.isEmpty) return;
|
||||
@@ -254,6 +259,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
if (accepted != null) _acceptedModels[id] = accepted;
|
||||
_startNotice = (id: id, notice: notice);
|
||||
_openedSessions[id] = <String, dynamic>{...session}..remove('running');
|
||||
_forgetRecentSession(previousId);
|
||||
_workspace.replaceSession(previousId, id);
|
||||
if (_workspace.paneCount == 0) _open(session);
|
||||
}
|
||||
@@ -271,6 +277,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
/// `/close` was accepted: the conversation leaves, back to the list, which
|
||||
/// re-reads the closed row.
|
||||
void _closed(String sessionId) {
|
||||
_forgetRecentSession(sessionId);
|
||||
for (final pane
|
||||
in _workspace.panes
|
||||
.where((pane) => pane.sessionId == sessionId)
|
||||
@@ -391,6 +398,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
@override
|
||||
void dispose() {
|
||||
HardwareKeyboard.instance.removeHandler(_cycleChatKey);
|
||||
HardwareKeyboard.instance.removeHandler(_slashFocusKey);
|
||||
_page.dispose();
|
||||
_workspaceBinding?.dispose();
|
||||
_workspace.removeListener(_workspaceChanged);
|
||||
|
||||
Reference in New Issue
Block a user