Merge main into open in chat
This commit is contained in:
@@ -2,6 +2,8 @@ part of 'screen.dart';
|
||||
|
||||
/// Pane layout, focus and route publication for one Chat destination visit.
|
||||
mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
final _sessionsKey = GlobalKey<ChatSessionsScreenState>();
|
||||
|
||||
Map<String, JsonMap> get _openedSessions;
|
||||
ChatComposerFocusRequests get _composerFocus;
|
||||
ChatPaneCommands get _paneCommands;
|
||||
@@ -46,6 +48,10 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
activeSessionId: selected,
|
||||
visibleSessionIds: _visibleSidebarSessions,
|
||||
onOpen: _openSidebarSession,
|
||||
onNewChat: () {
|
||||
final state = _sessionsKey.currentState;
|
||||
if (state != null) unawaited(state.newChat());
|
||||
},
|
||||
onExpand: () => _setSidebarMode(ChatSidebarMode.expanded),
|
||||
),
|
||||
],
|
||||
@@ -278,14 +284,12 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
String? _publishedWorkspaceSession;
|
||||
String _workspaceSignature = '';
|
||||
|
||||
/// Ctrl+Tab cycles the floating chat windows while any is shown, from the
|
||||
/// tiling as well (see [ChatWindows]). With none shown it cycles the
|
||||
/// retained panes, even when the sidebar or toolbar owns focus, and over a
|
||||
/// single pane it does nothing: it never brings up a chat that is not
|
||||
/// visible in the tiling. Command+Tab stays with the operating system's
|
||||
/// application switcher. While the app's terminal is shown, Ctrl+Tab moves
|
||||
/// between its tabs instead. A floating window that is not a chat, or any
|
||||
/// other window holding the keyboard, keeps the key.
|
||||
/// Ctrl+Tab cycles a single tiled pane through the open chats in sidebar
|
||||
/// order. The pane is replaced in place so its retained view keeps the
|
||||
/// transcript and draft. With multiple panes it cycles those panes. A
|
||||
/// focused floating chat window handles the key itself (see [ChatWindows]).
|
||||
/// Command+Tab stays with the operating system's application switcher, and
|
||||
/// the terminal keeps Ctrl+Tab for its own tabs.
|
||||
bool _cycleChatKey(KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (event is! KeyDownEvent ||
|
||||
@@ -298,8 +302,48 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
!_chatOwnsKeyboard()) {
|
||||
return false;
|
||||
}
|
||||
if (widget.windows?.raiseTopFromTiling() ?? false) return true;
|
||||
if (!_workspaceVisible || _workspace.paneCount < 2) return false;
|
||||
if (!_workspaceVisible || _workspace.paneCount == 0) return false;
|
||||
if (_workspace.paneCount == 1) {
|
||||
final pane = _workspace.activePane;
|
||||
if (pane == null) return false;
|
||||
final floating = widget.windows?.floatingSessionIds.toSet() ?? const {};
|
||||
final sessions = chatSessionsShown(
|
||||
_sessionsForSidebar.sessions
|
||||
.where(
|
||||
(row) =>
|
||||
row['closed_at'] == null &&
|
||||
row['closed'] != true &&
|
||||
!floating.contains('${row['id'] ?? ''}'),
|
||||
)
|
||||
.toList(),
|
||||
query: '',
|
||||
// Cycling is independent of a collapsed section: the sidebar's
|
||||
// ordering is still used, but every open-chat row remains reachable.
|
||||
isOpen: (_) => true,
|
||||
);
|
||||
final active = sessions.indexWhere(
|
||||
(row) => '${row['id'] ?? ''}' == pane.sessionId,
|
||||
);
|
||||
if (sessions.length < 2 || active < 0) return false;
|
||||
final direction = keyboard.isShiftPressed ? -1 : 1;
|
||||
final target = sessions[(active + direction) % sessions.length];
|
||||
final targetId = '${target['id'] ?? ''}';
|
||||
if (targetId.isEmpty) return false;
|
||||
_workspace.replacePaneSession(pane.id, targetId);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted ||
|
||||
!_workspaceVisible ||
|
||||
_workspace.activePane?.sessionId != targetId) {
|
||||
return;
|
||||
}
|
||||
final destination = ShellBarScope.maybeOf(context)?.registry.focus;
|
||||
if (destination == null || destination == AppDestination.chat) {
|
||||
_composerFocus.request(targetId);
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
return true;
|
||||
}
|
||||
final panes = _workspace.panes;
|
||||
final active = panes.indexWhere(
|
||||
(pane) => pane.id == _workspace.activePaneId,
|
||||
|
||||
@@ -485,6 +485,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
// The session list pads its first row by the bar's height itself, so it
|
||||
// scrolls behind the shell's floating bar like the other lists.
|
||||
final sessions = ChatSessionsScreen(
|
||||
key: _sessionsKey,
|
||||
gateway: widget.gateway,
|
||||
embedded: true,
|
||||
syncToken: widget.syncToken,
|
||||
|
||||
@@ -23,6 +23,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
required this.activeSessionId,
|
||||
this.visibleSessionIds = const {},
|
||||
required this.onOpen,
|
||||
required this.onNewChat,
|
||||
required this.onExpand,
|
||||
this.navigation,
|
||||
});
|
||||
@@ -31,6 +32,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
final String? activeSessionId;
|
||||
final Set<String> visibleSessionIds;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final VoidCallback onNewChat;
|
||||
final VoidCallback onExpand;
|
||||
final Widget? navigation;
|
||||
static const width = 72.0;
|
||||
@@ -135,6 +137,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
width: width,
|
||||
child: Column(
|
||||
children: [
|
||||
_button(context, 'New chat', const Icon(Icons.add), onNewChat),
|
||||
_button(
|
||||
context,
|
||||
'Expand chat list',
|
||||
|
||||
@@ -98,10 +98,10 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
final ChatSectionFolds? folds;
|
||||
|
||||
@override
|
||||
State<ChatSessionsScreen> createState() => _ChatSessionsScreenState();
|
||||
ChatSessionsScreenState createState() => ChatSessionsScreenState();
|
||||
}
|
||||
|
||||
class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
class ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
late final ChatSessionsController _controller =
|
||||
(widget.controller ??
|
||||
ChatSessionsController(
|
||||
@@ -233,6 +233,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
if (session != null && mounted) widget.onOpen(session);
|
||||
}
|
||||
|
||||
/// Starts the same machine picker and create dialog used by the list action.
|
||||
Future<void> newChat() => _newChat();
|
||||
|
||||
void _markOpened(JsonMap session) =>
|
||||
unawaited(_controller.markOpened(session));
|
||||
|
||||
|
||||
@@ -237,6 +237,23 @@ class ChatWorkspaceController extends ChangeNotifier {
|
||||
_changed();
|
||||
}
|
||||
|
||||
/// Replaces a pane after its caller has already validated [newId]. Unlike
|
||||
/// [replaceSession], this does not ask the window host to show a floating
|
||||
/// chat; keyboard cycling filters those chats before calling this method.
|
||||
void replacePaneSession(String paneId, String newId) {
|
||||
if (newId.isEmpty) return;
|
||||
final pane = panes.where((p) => p.id == paneId).firstOrNull;
|
||||
if (pane == null) return;
|
||||
final existing = panes.where((p) => p.sessionId == newId).firstOrNull;
|
||||
if (existing != null) {
|
||||
close(pane.id);
|
||||
activate(existing.id);
|
||||
return;
|
||||
}
|
||||
_root = _replace(_root!, pane.id, ChatWorkspacePane(pane.id, newId));
|
||||
_changed();
|
||||
}
|
||||
|
||||
ChatWorkspaceNode _replace(
|
||||
ChatWorkspaceNode node,
|
||||
String id,
|
||||
|
||||
@@ -156,10 +156,10 @@ class KeyboardShortcutRegistry {
|
||||
if (!web)
|
||||
const KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
action: 'Cycle chat panes and floating chats',
|
||||
action: 'Cycle chats and floating chat panes',
|
||||
keys: 'Ctrl+Tab, Ctrl+Shift+Tab',
|
||||
caveat:
|
||||
'While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
|
||||
'With one tiled pane, cycles open sidebar chats (excluding closed, hidden and floating chats); with multiple panes, cycles panes. While the terminal is shown, Ctrl+Tab moves between its tabs instead.',
|
||||
),
|
||||
const KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
|
||||
Reference in New Issue
Block a user