Fix Ctrl+Tab chat window navigation

Keep Ctrl+Tab scoped to shown floating chats when windows are visible, and otherwise cycle only visible tiled panes. Remove the single-pane recent-chat swap and use stable floating-window open order so raising a window does not alter navigation.
This commit is contained in:
2026-11-12 01:59:52 +00:00
parent 2330f50268
commit c05a4da476
8 changed files with 173 additions and 125 deletions
@@ -194,6 +194,7 @@ class ChatWindows {
/// session list, which nothing else reads while the Chat destination is
/// not built.
void _rowsChanged() {
_noteOpenOrder();
final ids = {for (final w in windows) w.contentId};
if (ids.isEmpty || !ready) return;
final sessions = runtime.sessions;
@@ -232,7 +233,7 @@ class ChatWindows {
}
/// Ctrl+Tab and Ctrl+Shift+Tab while a floating chat window holds the
/// keyboard: the next (previous) visible chat window, in stacking order and
/// keyboard: the next (previous) shown chat window, in open order and
/// wrapping, comes to the top. The window host then gives it the keyboard,
/// its composer. Left alone when another window or the tiling has the
/// keyboard, when the terminal claims tab keys, or with one window.
@@ -245,16 +246,47 @@ class ChatWindows {
_terminalClaimsTabs()) {
return KeyEventResult.ignored;
}
final target = chatWindowAfter(
windows.where(manager.isVisible).toList(),
scope.entry.id,
step,
);
final target = chatWindowAfter(shownInOpenOrder(), scope.entry.id, step);
if (target == null) return KeyEventResult.ignored;
manager.raise(target.id);
return KeyEventResult.handled;
}
/// The ids of the chat windows in the order they were opened; a window
/// restored from a saved layout keeps its saved place. Raising a window
/// changes the stacking order, not this one, so the Ctrl+Tab cycle is
/// stable. Kept in step on every change of the windows (see [_rowsChanged]).
final List<String> _openOrder = [];
void _noteOpenOrder() {
final ids = {for (final w in windows) w.id};
_openOrder.removeWhere((id) => !ids.contains(id));
for (final w in windows) {
if (!_openOrder.contains(w.id)) _openOrder.add(w.id);
}
}
/// The shown chat windows (not minimised, their group shown), in open order.
List<WindowEntry> shownInOpenOrder() {
_noteOpenOrder();
final shown = {
for (final w in windows)
if (manager.isVisible(w)) w.id: w,
};
return [for (final id in _openOrder) ?shown[id]];
}
/// Ctrl+Tab from the tiling or the chat list while chat windows are shown:
/// the top-most shown chat window comes to the top and its composer takes
/// the keyboard. False, doing nothing, when no chat window is shown.
bool raiseTopFromTiling() {
final top = windows.where(manager.isVisible).lastOrNull;
if (top == null) return false;
manager.raise(top.id);
kind.focusContent(top);
return true;
}
bool _terminalClaimsTabs() {
final context = FocusManager.instance.primaryFocus?.context;
return context != null &&