618add34b0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
3.4 KiB
Dart
87 lines
3.4 KiB
Dart
part of 'screen.dart';
|
|
|
|
/// A chat pane the keyboard can move to: a tiled pane or a floating window.
|
|
class _PaneCycleTarget {
|
|
const _PaneCycleTarget.pane(this.paneId, this.sessionId) : window = null;
|
|
_PaneCycleTarget.window(WindowEntry this.window)
|
|
: paneId = null,
|
|
sessionId = window.contentId;
|
|
|
|
final String? paneId;
|
|
final WindowEntry? window;
|
|
final String sessionId;
|
|
}
|
|
|
|
/// Alt+] and Alt+[ (also Cmd+] and Cmd+[ on Apple platforms, see
|
|
/// [chatPaneCycleShortcut]) move the keyboard to the next or previous chat
|
|
/// pane on screen: the tiled panes in their visual order (left to right,
|
|
/// then top to bottom, as the split tree lays them out; the center stage's
|
|
/// row in order), then the shown floating chat windows in the order they
|
|
/// were opened, wrapping around. The pane's composer takes the keyboard and
|
|
/// its focus ring flashes in the chat's colour. Nothing opens or closes.
|
|
///
|
|
/// It does nothing with one pane on screen, on a phone layout (the chat
|
|
/// stack and the quick switcher own moving between chats there), over a
|
|
/// popup or another destination, and while a terminal has the keyboard,
|
|
/// which keeps its Alt keys. Handled before the focus tree, so it works from
|
|
/// a composer and the web build stops the browser's own use of the keys.
|
|
mixin _ChatScreenPaneCycle on State<ChatScreen>, _ChatScreenWorkspace {
|
|
ChatRuntime get _runtime;
|
|
|
|
bool _paneCycleKey(KeyEvent event) {
|
|
final step = chatPaneCycleShortcut(event, HardwareKeyboard.instance);
|
|
if (step == null ||
|
|
!mounted ||
|
|
primaryFocusIsTypingSurface() ||
|
|
!_workspaceVisible ||
|
|
!showsListBesideDetail(context) ||
|
|
!_chatOwnsKeyboard()) {
|
|
return false;
|
|
}
|
|
final order = _paneCycleOrder();
|
|
final target = chatPaneCycleTarget(order, _paneCycleCurrent(order), step);
|
|
if (target == null) return false;
|
|
// A held chord is swallowed; only its first press moves.
|
|
if (event is KeyDownEvent) _focusPaneCycleTarget(target);
|
|
return true;
|
|
}
|
|
|
|
/// The panes on screen, in cycling order.
|
|
List<_PaneCycleTarget> _paneCycleOrder() {
|
|
final visible = _visibleSidebarSessions;
|
|
return [
|
|
for (final pane in _workspace.panes)
|
|
if (visible.contains(pane.sessionId))
|
|
_PaneCycleTarget.pane(pane.id, pane.sessionId),
|
|
for (final window
|
|
in widget.windows?.shownInOpenOrder() ?? const <WindowEntry>[])
|
|
_PaneCycleTarget.window(window),
|
|
];
|
|
}
|
|
|
|
/// Where the keyboard is in [order]: the floating chat window holding it,
|
|
/// otherwise the active tiled pane (also while the chat list has it).
|
|
int _paneCycleCurrent(List<_PaneCycleTarget> order) {
|
|
final window = keyboardWindow()?.entry;
|
|
if (window != null && window.kind == chatWindowKind) {
|
|
return order.indexWhere((target) => target.window?.id == window.id);
|
|
}
|
|
final active = _workspace.activePaneId;
|
|
return order.indexWhere((target) => target.paneId == active);
|
|
}
|
|
|
|
void _focusPaneCycleTarget(_PaneCycleTarget target) {
|
|
final window = target.window;
|
|
final windows = widget.windows;
|
|
if (window != null && windows != null) {
|
|
windows.manager.raise(window.id);
|
|
windows.kind.focusContent(window);
|
|
} else if (target.paneId case final paneId?) {
|
|
_workspace.activate(paneId);
|
|
_composerFocus.request(target.sessionId);
|
|
}
|
|
_runtime.paneFlash.flash(target.sessionId);
|
|
WidgetsBinding.instance.ensureVisualUpdate();
|
|
}
|
|
}
|