Merge branch 'main' into worktree-agent-a027d4a4581416c93

This commit is contained in:
2026-12-03 23:14:40 +00:00
39 changed files with 2472 additions and 126 deletions
@@ -0,0 +1,76 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
/// The step Alt+] (1) or Alt+[ (-1) moves the keyboard between the chat
/// panes on screen, or null for any other key. On Apple platforms Cmd+] and
/// Cmd+[ do the same.
///
/// Why these keys:
/// - Alt+Tab and Cmd+Tab are the system's window switchers, Ctrl+Tab cycles
/// the open chats (and the browser keeps it), and Alt+` already cycles the
/// floating windows.
/// - Browsers use Alt+Left/Right for back and forward; nothing on GNOME,
/// Hyprland, Windows or a browser binds Alt+[ or Alt+].
/// - Option+] and Option+[ type quotes on a Mac, so with Alt the key is
/// matched by its position (also catching layouts whose bracket keys type
/// something else). Cmd+] and Cmd+[ are the Mac's own next/previous pair
/// and leave Option free for typing.
/// - AltGr is how several layouts type brackets, so it never matches.
///
/// Shift never matches: Alt+Shift+[ types braces. A focused terminal keeps
/// these keys (Alt+[ is its escape prefix); the caller checks that.
int? chatPaneCycleShortcut(
KeyEvent event,
HardwareKeyboard keyboard, {
TargetPlatform? platform,
}) {
if (event is KeyUpEvent ||
keyboard.isShiftPressed ||
keyboard.isControlPressed ||
keyboard.isLogicalKeyPressed(LogicalKeyboardKey.altGraph)) {
return null;
}
final alt = keyboard.isAltPressed;
final meta = keyboard.isMetaPressed;
final int? step;
if (alt && !meta) {
step = switch (event.physicalKey) {
PhysicalKeyboardKey.bracketRight => 1,
PhysicalKeyboardKey.bracketLeft => -1,
_ => null,
};
} else if (meta && !alt && _apple(platform ?? defaultTargetPlatform)) {
step =
event.logicalKey == LogicalKeyboardKey.bracketRight ||
event.physicalKey == PhysicalKeyboardKey.bracketRight
? 1
: event.logicalKey == LogicalKeyboardKey.bracketLeft ||
event.physicalKey == PhysicalKeyboardKey.bracketLeft
? -1
: null;
} else {
step = null;
}
return step;
}
bool _apple(TargetPlatform platform) =>
platform == TargetPlatform.macOS || platform == TargetPlatform.iOS;
/// The forward and backward chords as this platform reads them, for the
/// shortcuts list.
String chatPaneCycleShortcutLabel([TargetPlatform? platform]) =>
_apple(platform ?? defaultTargetPlatform)
? 'Option+], Option+[, Cmd+], Cmd+['
: 'Alt+], Alt+[';
/// The entry [step] places from [current] in [order], wrapping around; null
/// when there is no other entry to move to. A [current] outside [order]
/// starts from the first entry going forward and the last going back.
T? chatPaneCycleTarget<T>(List<T> order, int current, int step) {
if (order.length < 2 || step == 0) return null;
if (current < 0 || current >= order.length) {
return step > 0 ? order.first : order.last;
}
return order[(current + step) % order.length];
}
@@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import '../../../ui/theme/app_design_tokens.dart';
/// Asks the chat pane showing a session to flash its focus ring, once the
/// keyboard moved there by the pane-cycling chord (see
/// [chatPaneCycleShortcut]). Shared by the tiling and the floating windows.
class ChatPaneFlashRequests extends ChangeNotifier {
String? _sessionId;
int _serial = 0;
/// The session last asked to flash.
String? get sessionId => _sessionId;
/// Advances on every request, so asking the same pane again flashes again.
int get serial => _serial;
void flash(String sessionId) {
_sessionId = sessionId;
_serial++;
notifyListeners();
}
}
/// How long the ring shows before it is gone.
const chatPaneFlashDuration = Duration(milliseconds: 700);
/// The ring's width, in logical pixels.
const chatPaneFlashWidth = 2.0;
/// One chat pane's focus cue: a ring in the chat's [color] drawn over the
/// pane, fading out, when [requests] names [sessionId]. Under reduced motion
/// the ring shows for the same time without fading. It also holds a focus
/// node around the pane: when nothing inside the pane took the keyboard
/// (the composer is not there or cannot be focused), the pane itself does.
class ChatPaneFocusFlash extends StatefulWidget {
const ChatPaneFocusFlash({
super.key,
required this.sessionId,
required this.requests,
required this.color,
required this.child,
});
final String sessionId;
final ChatPaneFlashRequests requests;
final Color? color;
final Widget child;
@override
State<ChatPaneFocusFlash> createState() => _ChatPaneFocusFlashState();
}
class _ChatPaneFocusFlashState extends State<ChatPaneFocusFlash>
with SingleTickerProviderStateMixin {
late final AnimationController _ring = AnimationController(
vsync: this,
duration: chatPaneFlashDuration,
);
final FocusNode _pane = FocusNode(
debugLabel: 'Chat pane',
skipTraversal: true,
);
int _seen = 0;
@override
void initState() {
super.initState();
_seen = widget.requests.serial;
widget.requests.addListener(_requested);
}
@override
void didUpdateWidget(ChatPaneFocusFlash oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.requests != widget.requests) {
oldWidget.requests.removeListener(_requested);
widget.requests.addListener(_requested);
_seen = widget.requests.serial;
}
}
@override
void dispose() {
widget.requests.removeListener(_requested);
_ring.dispose();
_pane.dispose();
super.dispose();
}
void _requested() {
final requests = widget.requests;
if (requests.serial == _seen) return;
_seen = requests.serial;
if (requests.sessionId != widget.sessionId) return;
_ring.forward(from: 0);
// The composer takes its request after a frame; look a frame later.
SchedulerBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
SchedulerBinding.instance
..addPostFrameCallback((_) {
if (mounted && !_pane.hasFocus) _pane.requestFocus();
})
..ensureVisualUpdate();
});
}
@override
Widget build(BuildContext context) {
final color = widget.color ?? Theme.of(context).colorScheme.primary;
final still = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
final radius = AppDesignTokens.of(context).radius ?? 0;
return Focus(
focusNode: _pane,
child: Stack(
fit: StackFit.passthrough,
children: [
widget.child,
Positioned.fill(
child: IgnorePointer(
child: AnimatedBuilder(
animation: _ring,
builder: (context, _) {
if (!_ring.isAnimating) return const SizedBox.shrink();
final fade = still
? 1.0
: 1 - Curves.easeIn.transform(_ring.value);
return DecoratedBox(
key: const ValueKey('chat-pane-focus-flash'),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius),
border: Border.all(
color: color.withValues(alpha: color.a * fade),
width: chatPaneFlashWidth,
),
),
);
},
),
),
),
],
),
);
}
}