Cycle open chat panes with Control Tab and focus their input
This commit is contained in:
@@ -20,6 +20,51 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
String? _publishedWorkspaceSession;
|
||||
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.
|
||||
bool _cycleChatKey(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (event is! KeyDownEvent ||
|
||||
event.logicalKey != LogicalKeyboardKey.tab ||
|
||||
!keyboard.isControlPressed ||
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
final panes = _workspace.panes;
|
||||
final active = panes.indexWhere(
|
||||
(pane) => pane.id == _workspace.activePaneId,
|
||||
);
|
||||
final direction = keyboard.isShiftPressed ? -1 : 1;
|
||||
final target =
|
||||
panes[((active < 0 ? 0 : active) + direction) % panes.length];
|
||||
_workspace.activate(target.id);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted ||
|
||||
!_workspaceVisible ||
|
||||
_workspace.activePaneId != target.id) {
|
||||
return;
|
||||
}
|
||||
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
|
||||
if (destination == null || destination == AppDestination.chat) {
|
||||
_composerFocus.request(target.sessionId);
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
void _workspaceChanged() {
|
||||
if (!mounted) return;
|
||||
final signature =
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
import 'conversation/chat_models.dart';
|
||||
@@ -126,6 +127,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
_publishedWorkspaceSession = initial;
|
||||
}
|
||||
_workspace.addListener(_workspaceChanged);
|
||||
HardwareKeyboard.instance.addHandler(_cycleChatKey);
|
||||
// Seen from now on, so the press that chooses the first chat counts.
|
||||
LastPointerKind.instance;
|
||||
_sessions.addListener(_nextChanged);
|
||||
@@ -365,6 +367,7 @@ class _ChatScreenState extends State<ChatScreen> with _ChatScreenWorkspace {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
HardwareKeyboard.instance.removeHandler(_cycleChatKey);
|
||||
_page.dispose();
|
||||
_workspace.removeListener(_workspaceChanged);
|
||||
_workspace.dispose();
|
||||
|
||||
Reference in New Issue
Block a user